Link to home
Start Free TrialLog in
Avatar of techcnb
techcnb

asked on

Extract specific file from a group of .zip files

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
 
ASKER CERTIFIED SOLUTION
Avatar of IceCode
IceCode
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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