Solved

Extract specific file from a group of .zip files

Posted on 2011-02-10
2
483 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now