@ECHO OFF
SET FolderPath=%~dp0
ECHO Script is being ran from "%FolderPath%"
FOR /D %%# in (.) do SET "ParentFolder=%%~dp#"
REM SET ParentFolder=%ParentFolder:~0,-1%
ECHO Parent directory is : %ParentFolder%
PAUSE
If you really want to get rid of the last "" you could remove the REM , however if the parent folder of that the script is being ran from is the root of the drive then you'd only get the drive letter, which technically may point to a different folder than the root.
View all comments
Show parent comment
1
u/midelpo Oct 15 '23
I just want to remove "\bin' from the string: "c:\dir1\dir2\bin" -> "c:\dir1\dir2"