Loop over folder string and parse out last folder name

后端 未结 13 1479
-上瘾入骨i
-上瘾入骨i 2020-12-03 05:39

I need to grab the folder name of a currently executing batch file. I have been trying to loop over the current directory using the following syntax (which is wrong at prese

13条回答
  •  盖世英雄少女心
    2020-12-03 06:03

    Slight alteration for if any of the folders have spaces in their names - replace space to ':' before and after operation:

    set mydir="%~p0"
    set mydir=%mydir:\=;%
    set mydir=%mydir: =:%
    
    for /F "tokens=* delims=;" %%i IN (%mydir%) DO call :LAST_FOLDER %%i
    goto :EOF
    
    :LAST_FOLDER
    if "%1"=="" (
      set LAST=%LAST::= %
      goto :EOF
    )
    
    set LAST=%1
    SHIFT
    
    goto :LAST_FOLDER
    

提交回复
热议问题