CMD to unzip files

dugdugdug

Active Member
Joined
May 11, 2012
Messages
342
I have a folder (C:\Zipped) that contains many zipped files (.gz)

I have installed 7-Zip

Can someone please tell me what is the command in DOS to unzip all the files in C:\Zipped

Better still, is there a single command that moves files and unzips (or the other way round)?

Thanks
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Hi

You can use the following sub-routine to unzip a given compressed folder to a chosen destination folder.


Sub-Routine:

Code:
Public Sub UnZip(ByVal varZipFile As Variant, ByVal strTargetPath As String)
    Dim objShAp As Object: Set objShAp = CreateObject("Shell.Application")
    Dim varTargetPath As Variant
 
    With Application
        If Not strTargetPath Like "*" & .PathSeparator Then
            strTargetPath = strTargetPath & .PathSeparator
        End If
    End With
    
    varTargetPath = strTargetPath


    With objShAp
        Call .Namespace(varTargetPath).CopyHere(.Namespace(varZipFile).Items)
    End With
End Sub

Use as follows:
Code:
Sub Demo()
    Call UnZip("C:\Folder\MyZipFile.zip", "C:\SomOtherFolder\")
End Sub
 
Upvote 0
Hi

You can use the following sub-routine to unzip a given compressed folder to a chosen destination folder.


Sub-Routine:

Code:
Public Sub UnZip(ByVal varZipFile As Variant, ByVal strTargetPath As String)
    Dim objShAp As Object: Set objShAp = CreateObject("Shell.Application")
    Dim varTargetPath As Variant
 
    With Application
        If Not strTargetPath Like "*" & .PathSeparator Then
            strTargetPath = strTargetPath & .PathSeparator
        End If
    End With
    
    varTargetPath = strTargetPath


    With objShAp
        Call .Namespace(varTargetPath).CopyHere(.Namespace(varZipFile).Items)
    End With
End Sub

Use as follows:
Code:
Sub Demo()
    Call UnZip("C:\Folder\MyZipFile.zip", "C:\SomOtherFolder\")
End Sub

Thanks but I have already written code in VBA to copy files and unzip.

It's just I was told it's an overkill to do it in Excel. Instead using DOS is quicker.

I worked out (via my VBA program) the syntax is as follows:

Code:
C:\Program Files\7-Zip\7z.exe x -aoa -r "C:\Raw Files\" *.* -o"C:\Unzipped\" *.*

Problem is, typing this into DOS and running it works.

When I write it in Notepad and save it as MyProg.bat, then double clicking it, it does nothing.
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,928
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top