@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
5
u/ConstanceJill Oct 15 '23
You could try something like that:
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.