I have a batch script that goes into a folder's subfolders (excluding one folder) gets .log files, archives them, and then deletes the originals.
Folder structure:
\Logs\logs1
\Logs\logs2
\Logs\logs3
Originally, I had this loop as just one line, which worked and looked like this:
FOR /F "usebackq tokens=* delims=" %%A IN (`DIR "%LogsFilespec%" /B /S ^|find ^"logs3^" /v `) DO %zipCommand% >> %ProcessLog% & DEL "%%~fA" & ECHO Deleting "%%~fA" >> %ProcessLog% & ECHO. >> %ProcessLog%
But, I was instructed to turn it into a simpler-looking FOR DO CALL, and as a result I am stuck, unsure of whats wrong. %targetDate% is YYYYMMDD.
**Edited for fuller code trying rojo's suggestion:
SET ProcessLog=C:\Users\Me\Documents\batch_files\%~n0_%jobLog%.txt
:DetermineArchiveApp
:: Create specifics for ITD Logs collection
SET ITDLogsLocation=C:\Users\Me\Documents\fakeG
SET ITDLogsName=trace*%targetDate%.log
SET ITDLogsFilespec=%ITDLogsLocation%\%ITDLogsName%
:: ********************************************************************************
:: * Check if server has WinZip or 7-Zip installed. setup environment variable *
:: * accordingly with executable path and name, and with any required parameters. *
:: ********************************************************************************
SET PathWinZip="C:\Program Files\WinZip\wzzip.exe"
SET Path7Zip_64bit="C:\Program Files\7-Zip\7z.exe"
SET Path7Zip_32bit="C:\Program Files (x86)\7-Zip\7z.exe"
SET Path7Zip_true="C:\Users\Me\Documents\batch_files\7za.exe"
:: Check for 32-bit version of 7-Zip. If found, configure
:: its command line parameter to produce a .zip file
IF EXIST %Path7Zip_32bit% SET zipCommand=%Path7Zip_32bit% a
::Check for WinZip
IF EXIST %PathWinZip% SET zipCommand=%PathWinZip% -a
:: Check for 64-bit version of 7-Zip. If found, configure
:: its command line parameter to produce a .zip file
IF EXIST %Path7Zip_64bit% SET zipCommand=%Path7Zip_64bit% a
:: Check for 64-bit version of 7-Zip. If found, configure
:: its command line parameter to produce a .zip file
IF EXIST %Path7Zip_true% SET zipCommand=%Path7Zip_true% a
:ArchiveProcess
ECHO ***************************************************** >> %ProcessLog%
::Write the date and time of job starting to a log
ECHO %DATE% %TIME% START >> %ProcessLog%
::Loop through the list that DIR gives for the given folder, and for each folder do zipCommand, excluding ITD\Data\AFS, and write to log
FOR /F "delims=" %%A IN (
'DIR "%LogsFilespec%" /B /S ^|find /v "logs3"'
) DO CALL :DoZip "%%~dpnA" "%%~fA" "%zipCommand%" "%ProcessLog%"
::Write end to log
ECHO %DATE% %TIME% %~nx0 END >> %ProcessLog%
ECHO ***************************************************** >> %ProcessLog%
:DoZip
setlocal
SET "archiveName=%~1"
SET "SourceFileSpec=%~2"
SET "zipCommand=%~3"
SET "RunLog=%~4"
>>"%RunLog%" (
echo Archiving %SourceFileSpec%...
"%zipCommand%" "%archiveName%.zip" "%SourceFileSpec%"
echo %TIME% Deleting %SourceFileSpec%...
DEL "%SourceFileSpec%"
echo;
)
GOTO :EOF
The errors I get from the cmd NOW are:
'""' is not recognized as an internal or external command, operable program or batch file.
Whats wrong with the syntax of either!?
EDIT 2: Heading home now, cant work remotely yet so I'll be back at it tommorow. The current issue is that: the 7zip command line does not like
"C:\Users\Me\Documents\batch_files\7za.exe" a
and also the >>"%RunLog%" block doesn't work, if comment out just the archival and deletion lines to see what's happening, I just get thrown
The system cannot find the drive specified.
The system cannot find the drive specified.
The system cannot find the drive specified.
The system cannot find the drive specified.
The system cannot find the path specified.