This batch file code will help you to unzip a file.
@echo off
setlocal
cd /d %~dp0
Call :UnZipFile "C:\Temp\" "c:\FolderName\batch.zip"
exit /b
:UnZipFile <ExtractTo> <newzipfile>
set vbs="%temp%\_.vbs"
if exist %vbs% del /f /q %vbs%
>%vbs% echo Set fso = CreateObject("Scripting.FileSystemObject")
>>%vbs% echo If NOT fso.FolderExists(%1) Then
>>%vbs% echo fso.CreateFolder(%1)
>>%vbs% echo End If
>>%vbs% echo set objShell = CreateObject("Shell.Application")
>>%vbs% echo set FilesInZip=objShell.NameSpace(%2).items
>>%vbs% echo objShell.NameSpace(%1).CopyHere(FilesInZip)
>>%vbs% echo Set fso = Nothing
>>%vbs% echo Set objShell = Nothing
cscript //nologo %vbs%
if exist %vbs% del /f /q %vbs%
N.B. C:\Temp is folder where it stores the Extracted (UnZip) File.
And, c:\FolderName\batch.zip is source path, (where Zip files are stored).
Please, Change the Full File Path ( Drive, Folder & Zip file name), according to your need.
answered Apr 16, 2018 at 7:32
Rajesh SinhaRajesh Sinha
9,0226 gold badges15 silver badges36 bronze badges
1
If you have Windows 10, you can use the much shorter Powershell equivalent
Expand-Archive -Force C:\path\to\archive.zip C:\where\to\extract\to
answered Feb 16, 2019 at 15:01
MegaBatchGamesMegaBatchGames
6071 gold badge5 silver badges4 bronze badges
2
If you have Windows 10 (and powershell), but still want to unzip from within .bat
/.cmd
-file (cmd.exe), you can use
powershell -command "Expand-Archive -Force '%~dp0my_zip_file.zip' '%~dp0'"
where my_zip_file.zip
is the file to be unzipped and %~dp0
points to the same folder are where the .bat
/.cmd
-file is (Change the folder, if needed).
answered Mar 17, 2020 at 17:30
Niko FohrNiko Fohr
1,3882 gold badges17 silver badges25 bronze badges
3
ZipFile="C:\Users\spvaidya\Music\folder.zip"
ExtractTo="C:\Users\spvaidya\Music\"
'If the extraction location does not exist create it.
Set fso = CreateObject("Scripting.FileSystemObject")
If NOT fso.FolderExists(ExtractTo) Then
fso.CreateFolder(ExtractTo)
End If
'Extract the contants of the zip file.
set objShell = CreateObject("Shell.Application")
set FilesInZip=objShell.NameSpace(ZipFile).items
objShell.NameSpace(ExtractTo).CopyHere(FilesInZip)
Set fso = Nothing
Set objShell = Nothing
The following vbscript can be saved as file.vbs and then run using batch script like:
file.vbs
save this in .bat file and run it.
answered Apr 30, 2019 at 5:57
I use this one-liner to extract all zip files in the current path to their own subdirectory based on their file name:
gci -Recurse -Filter *.zip |ForEach-Object {Expand-Archive -Path $_.Fullname -DestinationPath $_.BaseName -Force}
answered Jul 23, 2021 at 18:11
2
You must log in to answer this question.
Not the answer you’re looking for? Browse other questions tagged
.
Not the answer you’re looking for? Browse other questions tagged
.
This batch file code will help you to unzip a file.
@echo off
setlocal
cd /d %~dp0
Call :UnZipFile "C:\Temp\" "c:\FolderName\batch.zip"
exit /b
:UnZipFile <ExtractTo> <newzipfile>
set vbs="%temp%\_.vbs"
if exist %vbs% del /f /q %vbs%
>%vbs% echo Set fso = CreateObject("Scripting.FileSystemObject")
>>%vbs% echo If NOT fso.FolderExists(%1) Then
>>%vbs% echo fso.CreateFolder(%1)
>>%vbs% echo End If
>>%vbs% echo set objShell = CreateObject("Shell.Application")
>>%vbs% echo set FilesInZip=objShell.NameSpace(%2).items
>>%vbs% echo objShell.NameSpace(%1).CopyHere(FilesInZip)
>>%vbs% echo Set fso = Nothing
>>%vbs% echo Set objShell = Nothing
cscript //nologo %vbs%
if exist %vbs% del /f /q %vbs%
N.B. C:\Temp is folder where it stores the Extracted (UnZip) File.
And, c:\FolderName\batch.zip is source path, (where Zip files are stored).
Please, Change the Full File Path ( Drive, Folder & Zip file name), according to your need.
answered Apr 16, 2018 at 7:32
Rajesh SinhaRajesh Sinha
9,0226 gold badges15 silver badges36 bronze badges
1
If you have Windows 10, you can use the much shorter Powershell equivalent
Expand-Archive -Force C:\path\to\archive.zip C:\where\to\extract\to
answered Feb 16, 2019 at 15:01
MegaBatchGamesMegaBatchGames
6071 gold badge5 silver badges4 bronze badges
2
If you have Windows 10 (and powershell), but still want to unzip from within .bat
/.cmd
-file (cmd.exe), you can use
powershell -command "Expand-Archive -Force '%~dp0my_zip_file.zip' '%~dp0'"
where my_zip_file.zip
is the file to be unzipped and %~dp0
points to the same folder are where the .bat
/.cmd
-file is (Change the folder, if needed).
answered Mar 17, 2020 at 17:30
Niko FohrNiko Fohr
1,3882 gold badges17 silver badges25 bronze badges
3
ZipFile="C:\Users\spvaidya\Music\folder.zip"
ExtractTo="C:\Users\spvaidya\Music\"
'If the extraction location does not exist create it.
Set fso = CreateObject("Scripting.FileSystemObject")
If NOT fso.FolderExists(ExtractTo) Then
fso.CreateFolder(ExtractTo)
End If
'Extract the contants of the zip file.
set objShell = CreateObject("Shell.Application")
set FilesInZip=objShell.NameSpace(ZipFile).items
objShell.NameSpace(ExtractTo).CopyHere(FilesInZip)
Set fso = Nothing
Set objShell = Nothing
The following vbscript can be saved as file.vbs and then run using batch script like:
file.vbs
save this in .bat file and run it.
answered Apr 30, 2019 at 5:57
I use this one-liner to extract all zip files in the current path to their own subdirectory based on their file name:
gci -Recurse -Filter *.zip |ForEach-Object {Expand-Archive -Path $_.Fullname -DestinationPath $_.BaseName -Force}
answered Jul 23, 2021 at 18:11
2
You must log in to answer this question.
Not the answer you’re looking for? Browse other questions tagged
.
Not the answer you’re looking for? Browse other questions tagged
.
As others have alluded, 7-zip is great.
Note: I am going to zip and then unzip a file. Unzip is at the bottom.
My contribution:
Get the
7-Zip Command Line Version
Current URL
http://www.7-zip.org/download.html
The syntax?
You can put the following into a .bat file
"C:\Program Files\7-Zip\7z.exe" a MySuperCoolZipFile.zip "C:\MyFiles\*.jpg" -pmypassword -r -w"C:\MyFiles\" -mem=AES256
I’ve shown a few options.
-r is recursive. Usually what you want with zip functionality.
a is for «archive». That’s the name of the output zip file.
-p is for a password (optional)
-w is a the source directory. This will nest your files correctly in the zip file, without extra folder information.
-mem is the encryption strength.
FULL DOCUMENTATION (for «a» aka «Add») HERE
https://sevenzip.osdn.jp/chm/cmdline/commands/add.htm
There are others. But the above will get you running.
NOTE: Adding a password will make the zip file unfriendly when it comes to viewing the file through Windows Explorer. The client may need their own copy of 7-zip (or winzip or other) to view the contents of the file.
EDIT::::::::::::(just extra stuff).
There is a «command line» version which is probably better suited for this:
http://www.7-zip.org/download.html
(current (at time of writing) direct link)
http://sourceforge.net/projects/sevenzip/files/7-Zip/9.20/7za920.zip/download
So the zip command would be (with the command line version of the 7 zip tool).
"C:\WhereIUnzippedCommandLineStuff\7za.exe" a MySuperCoolZipFile.zip "C:\MyFiles\*.jpg" -pmypassword -r -w"C:\MyFiles\" -mem=AES256
Now the unzip portion: (to unzip the file you just created)
"C:\WhereIUnzippedCommandLineStuff\7zipCommandLine\7za.exe" e MySuperCoolZipFile.zip "*.*" -oC:\SomeOtherFolder\MyUnzippedFolder -pmypassword -y -r
As an alternative to the «e» argument, there is a x argument.
e: Extract files from archive (without using directory names)
x: eXtract files with full paths
Documentation here:
FULL DOCUMENTATION (for «e» aka «Extract») HERE
http://sevenzip.sourceforge.jp/chm/cmdline/commands/extract.htm
In the past it was not possible to create Zip files and Unzip archives in Windows without installing third-party programs like WinZip and 7-Zip.
But now Windows has a built-in capability to Zip files and folders and Unzip archives from the command line using PowerShell.
Starting from Windows 8 with PowerShell 3.0 and .NET Framework 4.5 installed by default, it is possible to use a kind of zip
and unzip
commands from the command line.
Cool Tip: Download a file using PowerShell! Read more →
Zip/Unzip From The Command Line In Windows
Depending on the version of PowerShell there are different ways to Zip files and folders and Unzip archives in Windows from the command line.
To determine a version of PowerShell on your machine, execute:
PS C:\> $PSVersionTable.PSVersion
PowerShell 5.0 (Windows 10) and greater
Starting from PowerShell 5.0 (Windows 10), it is possible to Zip files and folders and Unzip archives in Windows using Compress-Archive and Expand-Archive PowerShell commands.
Zip a file or a folder from the command line in Windows:
PS C:\> Compress-Archive -Path 'C:\input' -DestinationPath 'C:\output.zip'
Zip all files in a folder:
PS C:\> Compress-Archive -Path 'C:\folder\*' -DestinationPath 'C:\output.zip'
Unzip an archive from the command line in Windows:
PS C:\> Expand-Archive -Path 'C:\input.zip' -DestinationPath 'C:\output'
PowerShell 3.0 (Windows and greater
Starting from PowerShell 3.0 (Windows 8), it is possible to Zip folders and Unzip archives in Windows from the command line using the special methods in PowerShell.
Zip all files in a folder from the command line in Windows:
PS C:\> Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::CreateFromDirectory('C:\folder', 'C:\output.zip')
Unzip an archive from the command line in Windows:
PS C:\> Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('C:\input.zip', 'C:\output')
Was it useful? Share this post with the world!
Contents
- 1 How to Zip a Single File or Folder in Windows using ‘Send To’
- 2 How to Zip Multiple Files and Folders with ‘Send To’
- 3 How to Add Folders or Files to an Existing ZIP File
- 4 How to Make a ZIP File Out of Multiple Files or Folders with File Explorer’s Ribbon Bar
- 5 How to Zip or Unzip via the Command Line in Windows
- 6 How to Extract All Files and Folders from a Zip File
- 7 How to Extract a Single File from a Zip File
Though ZIP files have been around for decades, Windows 10 doesn’t make it immediately clear what they are, how to unzip a file, or how to zip a file yourself. While most of us understand that a zip file allows us to pack multiple files into a single one, it can be useful to understand the details before we proceed with this tutorial.
What are ZIP files?
ZIP is a file format of the archive type. It lets users add one or more files to a single package, which is then compressed. This compression process can take some time, but significantly reduces the size of the files without them losing any of their quality.
ZIP has been in Windows since 1998 and most commonly uses a compression algorithm called DEFLATE. Different types of files inside the package can be compressed using different methods, but, regardless, files inside of the ZIP file cannot be used unless they are decompressed and extracted.
The format is most commonly used to send files over the internet, particularly when a host has file size limits in place. However, it may also be used to reduce the size of local files that are currently unused and therefore free up space.
Compress files in Windows 10 (Zip / Unzip)
Today, we’re going to focus primarily on how to zip and unzip a file. For a full tutorial on compression in general, you can check our dedicated guide instead. Either way, bear in mind that compressing or zipping an encrypted file will cause it to be unencrypted once extracted. Be cautious with the data you compress.
How to Zip a Single File or Folder in Windows using ‘Send To’
Over the years, Microsoft has made it easier and easier to zip files. The easiest is through File Explorer’s Send To menu, which is perfect for quickly compressing a single file or folder.
- create a zip file in File Explorer
Right-click the file or folder you’d like to zip, then move your cursor down the menu and click “Send to > Compressed (zipped) folder”.
- Name your zipped file or folder
Windows will automatically create a zip file and place your cursor in its name box. Type an appropriate name or keep the pre-populated one and press Enter.
How to Zip Multiple Files and Folders with ‘Send To’
The above method can also be used to create a zip file out of more than one file or folder. All you need to do is select more than one in your File Explorer window.
- How to create a zip file out of multiple files or folders
To select multiple files, click on your first file, then Ctrl + click to select the others you’d like to compress. If you a long list of files that all need to be compressed, you can select the file at the top and then Shift + click the one at the bottom to select all of them.
You can then right-click any of the files or folders and choose “Send to > Compressed (zipped) folder”.
- Name your zip file
Windows 10 will show you a zip file and ask you to choose an appropriate name. Do so, then press Enter.
How to Add Folders or Files to an Existing ZIP File
So, you finished creating your zip file, only to realize you missed a file or folder. Not to worry – Windows 10 makes this easy to solve, too.
- Drag your files or folders to your existing zip folder
- Wait for the ‘+ Copy’ tooltip and release your mouse button
How to Make a ZIP File Out of Multiple Files or Folders with File Explorer’s Ribbon Bar
If you don’t like fiddling around with the right-click menu, File Explorer also provides options via its ever-useful ribbon bar.
- Select your files or folders and press ‘Zip’
You can select multiple files with Ctrl + click or Shift + click. The former will let you select each individually, while the latter will select everything between two selected files.
Once everything you want to click is highlighted in blue, select the “Share” button at the top of the ribbon, then click “Zip”.
- Name your newly zipped files or folders
You can keep the default name or type one of your own. Once you’re done, click away or press “Enter”.
How to Zip or Unzip via the Command Line in Windows
In case you prefer the command line, we’ll quickly show you how to unzip files or zip them again with PowerShell. This is generally a bit more fiddly, but it can be powerful if you’re trying to automate.
- Open PowerShell as an Admin
Press Start + X to open the secret Start menu, then click “Windows PowerShell (Admin)”.
- Enter the zip command in Windows PowerShell
To zip files or folders, run the following command, replacing the <Path to> text (including the greater and lesser than symbols) with the location of your file or folder and where you want to save it:
Compress-Archive -LiteralPath <PathToFiles> -DestinationPath <PathToDestination>
For example, for a single file, you could type:
Compress-Archive -Path C:\Users\winbu\Music\Benny Goodman Swings Again\airmail.mp3 -DestinationPath C:\Users\winbu\Music\favorite music.zip
If you wanted to compress the entire folder, you could instead type:
Compress-Archive -Path C:\Users\winbu\Music\Benny Goodman Swings Again\ -DestinationPath C:\Users\winbu\Music\favorite music.zip
Alternatively, to compress all the files in a folder but not the folder itself, you can use a wildcard (*) to exclude the parent folder. This method won’t include the subdirectories and files of the root folder:
Compress-Archive -Path C:\Users\winbu\Music\Benny Goodman Swings Again\* -DestinationPath C:\Users\winbu\Music\favorite music.zip
If you want to compress only a folder’s root files and subdirectories, you can use the *.* wildcard:
Compress-Archive -Path C:\Users\winbu\Music\Benny Goodman Swings Again\*.* -DestinationPath C:\Users\winbu\Music\favorite music.zip
Finally, if you have a folder with files or various formats, but only want to zip one type, you can do so with the *.filetype wildcard. In our example, we may want to zip mp3 files, but not their .jpg album art:Compress-Archive -Path C:\Users\winbu\Music\Benny Goodman Swings Again\*.mp3 -DestinationPath C:\Users\winbu\Music\favorite music.zip
- Enter the unzip command in Windows PowerShell
If you’re wondering how to unzip files with PowerShell, try the following command:
Expand-Archive -LiteralPath <PathToZipFile> -DestinationPath <PathToDestination>
Naturally, replace <PathToZipFile> with the path to your zip, and <PathToDestination> with where you want it to be unzipped to. If you don’t specify a destination path, it will unzip to the same folder the zip is stored in.
How to Extract All Files and Folders from a Zip File
If you received a ZIP file or are wondering how to unzip a file you previously compressed, File Explorer should be your go-to. We can use that handy right-click menu again to reverse the process.
- Right-click the ZIP file and select ‘Extract All…’
- Choose where to extract the zip to
Windows will surface a window called “Extract Compressed (Zipped) Folders”. Under the “Select a Destination and Extract Files” heading, choose “Browse…”. Navigate to the location you’d like to extract to in the File Explorer menu, click “Open”, and then back in the main extraction window press “Extract”.
Depending on the size of the archive, the extraction process may take some time.
Sometimes you don’t want to wait for an entire archive to extract when you only require a single file. In such cases, it is possible to unzip a single file. First, double-click the .zip file to open it, then follow the step below.
- Drag the file out of the .zip archive
It’s really that simple. Just make sure you’re dragging the file to either your desktop or another File Explorer window with your destination folder.
That closes out this guide, which should have taught you everything you need to know about zip files in Windows 10. However, if you have a penchant for learning, you can also try our batch renaming and folder options guides.