Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Extract specific file from a group of .zip files

Posted on 2011-02-10
2
Medium Priority
?
513 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
[X]
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
2 Comments
 
LVL 4

Accepted Solution

by:
IceCode earned 2000 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

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…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

618 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