Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Extract specific file from a group of .zip files

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
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 …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

790 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