Unzipping all files in a directory

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!
LVL 1
MultimaticAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shift-3Commented:
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
Shift-3Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MultimaticAuthor Commented:
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
MKadricCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Utilities

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.