1

I have a Windows batch file that process a bunch of files. As part of this I use the following line:

forfiles /p "%~dpn1%LogDir%" /m "%SupportLog%*" /c "cmd /c logreader.py @file > \"%~dpn1%ParsedLogDir%\@file_Logreader.txt\"

This works OK, but essentially loops through all my files (%SupportLog%*) and passes each one by one into the "logreader.py" script.

What I really want to do is create a list or parameter of all these files and pass all of them at once into the Python script, such the the command that should be run would resemble:

logreader.py "logfile.log" "logfile.log.1" "logfile.log.3" .....

I tried to use the SET command within the forfile command such that:

forfiles /p "%~dpn1%LogDir%" /m "%SupportLog%*" /c "cmd /c set PARAMS=%PARAMS%@file "

However, when run this and leave the ECHO ON, I see:

forfiles /p "C:\Path\log" /m "logfile.log*" /c "cmd /c set PARAMS=@file "

Which is incorrect. And when I "echo %PARAMS%", I get no result.

Is there a way of achieving this?

Many thank

1 Answers1

1

Changing environment variables in a child cmd instance (that's what the cmd /c invokes) does not affect environment in the parent cmd process. Next code snippet could help:

SETLOCAL EnableExtensions EnableDelayedExpansion
set "LogDir=%~dpn1log"         my guess only
set "SupportLog=logfile.log"   my guess only
set "PARAMS="                  initial value
rem 1st try for /R "%LogDir%" %%a in ("%SupportLog%*") do set PARAMS=!PARAMS! "%%~a"
rem 2nd try for %%a in ("%LogDir%\%SupportLog%*") do set "PARAMS=!PARAMS! "%%~a""
rem 3rd try
for %%a in ("%LogDir%\%SupportLog%*") do set "PARAMS=!PARAMS! "%%~nxa""
echo logreader.py %PARAMS%

Note that imperative logreader.py is merely echoed for debugging purposes.

However, I don't apprehend target of > redirection, sorry...

Resources (required reading):

Edit:

JosefZ
  • 13,855