# CMD to unzip files



## dugdugdug (Jan 2, 2013)

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


----------



## Jon von der Heyden (Jan 2, 2013)

Hi

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

*
Sub-Routine:*

```
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:*

```
Sub Demo()
    Call UnZip("C:\Folder\MyZipFile.zip", "C:\SomOtherFolder\")
End Sub
```


----------



## dugdugdug (Jan 2, 2013)

Jon von der Heyden said:


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



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:


```
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.


----------



## dugdugdug (Jan 2, 2013)

Sorted:


```
cd\
cd program files
7-Zip\7z.exe x -aoa -r "C:\Raw Files\" *.* -o"C:\Unzipped\" *.*
```


----------



## Jon von der Heyden (Jan 3, 2013)

Thanks for sharing that with the rest of us!


----------

