Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've got an interesting scripting challenge in front of me. I'm fairly certain there's a way to do it, but I feel like I'm probably lacking some particular tools and/or functional knowledge.

There's some fifty-plus ZIP files that each contain, among other things, text files that need to be merged with one another. The structure is something like this:

C:\Reports\FirstJob-1.zip  
|-MyName  
  |-FirstJob
    |-1
      |-[Some other folders]
      |-TXTReports
        |-English
          |-[Some other files]
          |-Report.txt  

C:\Reports\FirstJob-2.zip  
|-MyName  
  |-FirstJob
    |-1
      |-[Some other folders]
      |-TXTReports
        |-English
          |-[Some other files]
          |-Report.txt 

C:\Reports\SecondJob-1.zip  
|-MyName  
  |-SecondJob
    |-1
      |-[Some other folders]
      |-TXTReports
        |-English
          |-[Some other files]
          |-Report.txt

If I had all the Report.txt files in one regular folder, and uniquely named, I could probably just write a FOR statement that targets *.txt and runs something like type filename.txt >> Consolidated.txt on each. However, these all have the same file name and are embedded deep within separate ZIP files.

The potentially useful tools I currently have at my disposal are Windows XP Professional SP3, PowerShell, and WinZip. I'd rather not download or install anything else, but I do understand that third-party tools (or additional tools from Microsoft or WinZip) may be necessary. Whatever tools I use should run natively in Windows. I really don't want to have to mess with Cygwin or other emulators on this system.

At the very least, I need a tool that will allow me to analyze and manipulate ZIP files from the command line. Also, are there any other particular complications to this that I've not yet thought of?

share|improve this question
add comment

2 Answers

May I suggest another option? If you are using Windows XP, then you also have VBScript at your disposal. Several years ago I wrote a series of articles that demonstrated how VBScript in WSH can be leveraged to create and manipulate zip files using Windows XP's built-in support for Compressed Folders. You should give that a go. Your script wouldn't have any third-party dependencies and scripting the file system logic is pretty straightforward.

Compressed Folders in WSH

Understanding the CompressedFolder Class

Implementing the CompressedFolder Class

The long and short of this is that zip files can be opened as compressed folders using the Shell object's Namespace method. This is essentially the same as exploring them like a directory with Windows Explorer.

share|improve this answer
    
Thanks for the suggestion. I'm not very familiar with VBScript, so I was hoping there was a command-line utility that would allow me to put all necessary commands in a batch file. Still, I may give this a shot. –  Iszi Apr 5 '12 at 5:22
    
Batch files are extremely limited in their ability to implement logic. This really is your best route. I definitely suggest taking a look at it. –  Nilpo Apr 5 '12 at 12:47
add comment

Info-ZIP's UnZip (Windows binaries here) will let you extract zipfiles from the command line with unzip -x. The rest is a matter of finding and concatenating the files, for example:

find . -name Report.txt -print0 | xargs -0 cat > Consolidated.txt

The above are Unix commands which you can find in either Cygwin or GnuWin32.

Potential implications are that if you have a lot of files the xargs command gets too long and if the files are very big you may run out of diskspace (you can work around this by unzipping and concatenating the files one by one, deleting the unpacked archive folder after each file).

share|improve this answer
    
Thanks for the suggestion. I should probably mention that I'd rather not mess with Cygwin or other Unix emulators. I want to do it all natively in Windows. –  Iszi Feb 24 '12 at 20:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.