Question : unzip, selective copy of TXT files


Please see attached files.
I need to regularly process incomming zip files that always have only one TXT file in them.
Some months there are three zip files, other months there are five.
Keeping this in mind, I want to do the following with a script, wiothout it caring if there are 3,4 or 5 zips in a directory:

look in "C:\incoming\1", "C:\incoming\2", "C:\incoming\3",  to the n directories...
(dont confuse the number of directories within incoming as whatever number of zip files there are)
The script will look in numerical order at Both directories and zip files.
The zip files will always be called, for example week1.zip, week2.zip, week3.zip, week4.zip

On a zip by zip basis, unzip to a temp area, then remove line 1 (which is always the same) then copy the content to C:\output\final.txt.
This is continues through all the directories and zip files in order. The data for ALL the zips are appended to the same file final.txt

Thanks

C
Attachments:
 
w1
 
 
w2
 
 
w3
 
 
final
 

Answer : unzip, selective copy of TXT files

Here's a version that should work for 7zip.

~bp
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
@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"
    )
  )
)
Random Solutions  
 
programming4us programming4us