I have a script that recursively loops through all .txt
files in the working directory and subdirectories and does something with that files. Now I would like to exclude all files in certain subdirectories that are listed in a exclude.txt
file:
@ECHO OFF
SETLOCAL EnableDelayedExpansion
for /r %%f in (*.txt) do (
CALL:processFile %%f %%~df%%~pf
)
GOTO:EOF
:processFile
SET file_=%~1
SET path_=%~2 <- %%~df%%~pf is the full path :(
find "!path_!" exclude.txt
IF !ERRORLEVEL! EQU 1 (
REM do something here
)
GOTO:EOF
However, %%/~df%%~pf
expands to the absolute path. How can I get the path relative to the workingdirectory? I want to list only the subdirectories in exclude.txt
and not the full paths.
PS: I could of course read the relative paths from exclude.txt
, append %cd%
and write them to some exclude.temp
and then search in this temporary file, but I hope there is a nicer way.