Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have the path:
C:\Windows\System32\regsvr32.exe

and i want to remove last backslash with "regsvr32.exe"
its should be

C:\Windows\System32

i don't want to use the code:

set "path=C:\Windows\System32\regsvr32.exe"
if "%path%:~-1" EQU "\" set "path=%path:~0,-1%"
echo %path%
pause


What I have tried:

i try many combines but doesn't success
Posted
Updated 2-Aug-19 15:46pm

@echo off
setlocal enabledelayedexpansion enableextensions

set myPath=C:\efi\Boot\bootx64.efi
call :file_name_from_path result !myPath!
echo %result%
goto :eof

:file_name_from_path <resultVar> <pathVar>
(
    set "%~1=%~dp1"
    exit /b
)

:eof
endlocal

Based off of information found on S/O
How to get folder path from file path with CMD - Stack Overflow[^]
 
Share this answer
 
 
Share this answer
 
Comments
MasterGamerFX 3-Aug-19 6:56am    
ok and i want to extract from C:\efi\Boot\bootx64.efi
i want extract boot only
how do that
MasterGamerFX 17-Aug-19 12:05pm    
if found the code

@echo off
for %%a in ("c:\test\pack\a.txt") do for %%b in ("%%~dpa\.") do set "parent=%%~nxb"
echo %parent%
pause

but i don't use for loop for this
how can use this code without "for" loop?
Mohibur Rashid 17-Aug-19 12:32pm    
hi, I am not very good at Batch. Anyway, to get the directory use the first one and basename command equivalent

I do not think there is better solution than these. But, I am not sure what powershell offers.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900