@echo off
rem Define paths to folders and files to work with
set BaseDir=c:\a\m\input
set TempDir=c:\a\m\temp
set FinalFile=c:\a\m\output\final.txt
set UnZipExe=c:\program files\7-zip\7z.exe
rem If unzip work area does not exist create it
if not exist "%TempDir%\" mkdir "%TempDir%"
rem If output file exists, delete it
if exist "%FinalFile%" del "%FinalFile%"
rem Loop through subfolders 1 to 300, checking if they exits
for /L %%A in (1, 1, 300) do (
if exist "%BaseDir%\%%A\" (
rem Process any WEEK*.ZIP files in this folder (in name order)
for /F "tokens=*" %%B in ('dir /b /a-d /on "%BaseDir%\%%A\week*.zip"') do (
rem Unzip the TXT file in this ZIP to temp folder
"%UnZipExe%" x "%BaseDir%\%%A\%%~nB.zip" %%~nB.txt -y -o"%TempDir%" >NUL
rem Append this TXT file to merged uoutput file (skipping any header line)
findstr /I /V /C:"list of animals I saw this week" "%TempDir%\%%~nB.txt" >>"%FinalFile%"
rem Remove this TXT file from temp folder
del "%TempDir%\%%~nB.txt"
)
)
)
|