I need to find the name of the parent directory for a file in DOS
for ex.
Suppose this is the directory
C:\\test\\pack\\a.txt
see this question
@echo OFF set mydir="%~p1" SET mydir=%mydir:\=;% for /F "tokens=* delims=;" %%i IN (%mydir%) DO call :LAST_FOLDER %%i goto :EOF :LAST_FOLDER if "%1"=="" ( @echo %LAST% goto :EOF ) set LAST=%1 SHIFT goto :LAST_FOLDER