I would like to read a list of paths from a file and determine each time the last folder. I have found something to start with, failed, read various threads dealing with nested for loops and variable expansions however without success. I do not get a "Last folder:" response. Anyone seeing the problem here? Any help is greatly appreciated!
External file (paths.txt):
C:\FirstFolder\NextFolder\LastFolder
C:\Somewhere\Deeper\FinallyThere
C:\Temp
Windows batch script:
@echo OFF
setLocal EnableDelayedExpansion
for /F "tokens=* eol=#" %%f in (%CD%\paths.txt) do (
echo Get new path from file: %%f
set mydir=%%f
set m=%mydir:\=;%
call :GET_SYMLINK %%m
)
setLocal DisableDelayedExpansion
goto :eof
:GET_SYMLINK
for /F "tokens=* delims=;" %%i IN (%1) DO call :LAST_FOLDER %%i
goto :eof
:LAST_FOLDER
if "%1"=="" (
echo Last folder: %LAST%
goto :eof
)
set LAST=%1
SHIFT
goto :LAST_FOLDER