Get parent directory name for a particular file using DOS Batch scripting

后端 未结 9 1277
無奈伤痛
無奈伤痛 2020-12-08 21:33

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
9条回答
  •  轮回少年
    2020-12-08 22:13

    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

提交回复
热议问题