Link to home
Start Free TrialLog in
Avatar of Multimatic
MultimaticFlag for Canada

asked on

Unzipping all files in a directory

Hi,
After getting the solution to batch zipping files (see https://www.experts-exchange.com/questions/23911898/How-do-I-batch-zip-files-with-igs-extension-and-retain-original-name-and-location-then-delete-the-igs-files.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!
Avatar of Shift-3
Shift-3
Flag of United States of America image

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

ASKER CERTIFIED SOLUTION
Avatar of Shift-3
Shift-3
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
Avatar of Multimatic

ASKER

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
Avatar of MKadric
MKadric

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.