Solved

Extract specific file from a group of .zip files

Posted on 2011-02-10
2
497 Views
1 Endorsement
Last Modified: 2012-05-11
I would like to extract a specific file from a folder full of .zip files.
Each .zip file contains a text file that's file name begins with RTC
The following code will extract all the documents out of each zip folder, however i only want the RTC...file. Any help would be appreciated.
Heres what i have so far

Option Explicit
Dim objFSO, objShell, strFolder, objFile, strSource, strDestination
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
 
strFolder = "C:\Temp"
For Each objFile In objFSO.GetFolder(strFolder).Files
      If Right(LCase(objFile.Name), 4) = ".zip" Then
            strSource = objFile.Path
            strDestination = "C:\Unzipped"
 
            'Extract the Zip file into  Directory
            Extract strSource, strDestination
      End If
Next
 
MsgBox "Done"
 
'Zip Extraction sub
Sub Extract(ByVal myZipFile, ByVal myTargetDir)
      Dim strUZip, strCommand
      strUZip = "N:\Utilities\UltimateZip Command Line Tool\uzext.exe"
      
      If Right(myTargetDir, 1) <> "\" Then myTargetDir = myTargetDir & "\"
      If objFSO.FolderExists(myTargetDir) = False Then objFSO.CreateFolder(myTargetDir)
      strUZip = objFSO.GetFile(strUZip).ShortPath
      myZipFile = objFSO.GetFile(myZipFile).ShortPath
      myTargetDir = objFSO.GetFolder(myTargetDir).ShortPath
      strCommand = "cmd /c " & strUZip & " -e -o -d -p" & myTargetDir & " " & myZipFile
      objShell.Run strCommand, 0, True
End Sub
 
1
Comment
Question by:techcnb
2 Comments
 
LVL 4

Accepted Solution

by:
IceCode earned 500 total points
ID: 34866272
Maybe the easiest thing to do is loop through all of the files after you are done extracting them and delete any file that doesn't start with "RTC"?  Unless you are trying to avoid the full extractions I guess.  I would write it out but your code indicates to me that you will understand how to do this.
0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 34866376
Try changing the following line:

strCommand = "cmd /c " & strUZip & " -e -o -d -p" & myTargetDir & " " & myZipFile

Open in new window


To:

strCommand = "cmd /c " & strUZip & " -e -o -d -p" & myTargetDir & " " & myZipFile & " RTC*"

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question