Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Unzipping all files in a directory

Posted on 2008-11-18
4
Medium Priority
?
983 Views
Last Modified: 2013-12-01
Hi,
After getting the solution to batch zipping files (see http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_23911898.html?cid=239), I now need a method to unzip all files in a given directory.

The reason is that there are occasions when a user needs to access all original files in a given folder from time to time.  It's tedious for them to unzip them one by one.

Ideally adding an 'unzip this folder' option to the right click menu would be fantastic!  I know it can be done for a 3rd party app such as gzip, but ideally I would like to take advantage of my new batch script method which creates idividual '.zip' files using (I think) the built in Windows zip mechanism.


Cheers!
0
Comment
Question by:Multimatic
  • 2
4 Comments
 
LVL 38

Expert Comment

by:Shift-3
ID: 22987731
Paste the script below into a text file with a .vbs extension.  Running it with a folder as an argument will extract the contents of all .zip files in that folder into its root.  To extract them into separate subfolders, change the blnIntoFolders variable to True.

To add this to the right-click context menu, place the script in a predefined location on the C: drive (C:\UnZipAll.vbs in this example) and run the following commands:
reg add "HKCR\Directory\Shell\UnZipAll" /ve /d "Unzip All" /freg add "HKCR\Directory\Shell\UnZipAll\Command" /ve /d "wscript C:\UnZipAll.vbs ""%1""" /f


blnIntoFolders = False
 
On Error Resume Next
 
If WScript.Arguments.Count <> 1 Then
    WScript.Echo "Invalid number of arguments."
    WScript.Quit
End If
 
strFolder = WScript.Arguments(0)
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
Set objFolder = objFSO.GetFolder(strFolder)
Set colFiles = objFolder.Files
 
For Each objFile in colFiles
    If blnIntoFolders Then
        strNew = objFile.Path & "_unzipped"
        objFSO.CreateFolder strNew
    Else
        strNew = strFolder
    End If
    
    UnZipFile objFile.Path, strNew
Next
 
 
Sub UnZipFile(strArchive, strDest)
    Set objApp = CreateObject( "Shell.Application" )
    
    Set objArchive = objApp.NameSpace(strArchive).Items()
    Set objDest = objApp.NameSpace(strDest)
 
    objDest.CopyHere objArchive
End Sub

Open in new window

0
 
LVL 38

Accepted Solution

by:
Shift-3 earned 2000 total points
ID: 22989977
Correction.


blnIntoFolders = False
 
On Error Resume Next
 
If WScript.Arguments.Count <> 1 Then
    WScript.Echo "Invalid number of arguments."
    WScript.Quit
End If
 
strFolder = WScript.Arguments(0)
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
Set objFolder = objFSO.GetFolder(strFolder)
Set colFiles = objFolder.Files
 
For Each objFile in colFiles
    If LCase(Right(objFile.Name, 4)) = ".zip" Then
        If blnIntoFolders Then
            strNew = objFile.Path & "_unzipped"
            objFSO.CreateFolder strNew
        Else
            strNew = strFolder
        End If
    
        UnZipFile objFile.Path, strNew
    End If
Next
 
 
Sub UnZipFile(strArchive, strDest)
    Set objApp = CreateObject( "Shell.Application" )
    
    Set objArchive = objApp.NameSpace(strArchive).Items()
    Set objDest = objApp.NameSpace(strDest)
 
    objDest.CopyHere objArchive
End Sub

Open in new window

0
 
LVL 1

Author Comment

by:Multimatic
ID: 22995853
Hi,
Keeping you busy Shift-3!

Seems to work but is it possible to select the file types that I want to extract within the directory, i.e only .igs files?


Cheers
0
 

Expert Comment

by:MKadric
ID: 26487325
Sorry I was not quite clear.  

I do not want to extract or create.... Only want the progam to pop up to allow user to do what they want.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
Considering today’s continual security threats, which affect Information technology networks and systems worldwide, it is very important to practice basic security awareness. A normal system user can secure himself or herself by following these simp…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month15 days, left to enroll

577 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