How do I loop through files in folder to create a parameter list to pass into another script in a Windows batch file? -
i have windows batch file processes bunch of files. part of use following line:
forfiles /p "%~dpn1%logdir%" /m "%supportlog%*" /c "cmd /c logreader.py @file > \"%~dpn1%parsedlogdir%\@file_logreader.txt\"
this works ok, loops through files (%supportlog%*
) , passes each 1 one logreader.py script.
what want create list or parameter of these files , pass of them @ once python script, such command should run resemble:
logreader.py "logfile.log" "logfile.log.1" "logfile.log.3" .....
i tried use set
command within forfiles
command that:
forfiles /p "%~dpn1%logdir%" /m "%supportlog%*" /c "cmd /c set params=%params%@file "
however, when run , leave echo on
, see:
forfiles /p "c:\path\log" /m "logfile.log*" /c "cmd /c set params=@file "
this incorrect. , when echo %params%
, no result.
is there way of achieving this?
forfiles complicated or may buggy. not support quotes within /c "cmd /c ...."
must replaced hex characters 0x22
, or \"
.
@echo off setlocal enabledelayedexpansion /f "delims=" %%a in ('dir /b /a-d "logfile.log.?"') ( set _logfile=!_logfile! "%%a" ) echo logreader.py %_logfile%
output:
logreader.py "logfile.log.1" "logfile.log.2" "logfile.log.3" "logfile.log.4" "logfile.log.5"
Comments
Post a Comment