Windows unzip from command line

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 Sinha's user avatar

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

MegaBatchGames's user avatar

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 Fohr's user avatar

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

spoorthi vaidya's user avatar

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

Aaron Hudon's user avatar

2

You must log in to answer this question.

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 Sinha's user avatar

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

MegaBatchGames's user avatar

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 Fohr's user avatar

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

spoorthi vaidya's user avatar

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

Aaron Hudon's user avatar

2

You must log in to answer this question.

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

Get your files zipped or unzipped with a quick command on Windows.

closeup of a screen displaying command prompt

Are you running out of space on your Windows PC? The best thing you can do to free up some space is to compress big files through zipping. There are plenty of third-party tools that can come in handy in this situation.

However, if you prefer to use Command Prompt or Windows PowerShell over anything else, there are commands you can use in these utilities to zip or unzip files. So, let’s check out how to zip or unzip files using Command Prompt and Windows PowerShell.

How to Zip Files Using Command Prompt

You can zip files through Command Prompt using the tar command. It’s a command line tool that helps you to extract files and create archives. However, this command only works in Windows 10 or later.

Here’s how to zip files using Command Prompt:

  1. Open the Start Menu by pressing the Win key.
  2. In the search bar, type Command Prompt and Run as administrator from the right pane.
  3. In the console, type the following command and press Enter. Replace ‘Place’ with the location of the file.
     cd Place 
    Place of the file
  4. Type dir and press Enter. It’ll show the files inside the selected folder.
    Dir command in CMD
  5. To zip all the files inside the selected folder, type the following command and press Enter. Replace ‘Compressed‘ with the name you want to give your folder where the zip file will be stored. Also, replace ‘FileExt‘ with the extension of the file you’re zipping.
     tar -a -c -f Compressed.zip *.FileExt 
    Tar command in CMD
  6. To zip a single file, execute the following command. Again, replace ‘Compressed‘ with the name you want to give your folder where the zip file will be stored, ‘FileExt‘ with your file’s extension, and ‘FileName‘ with the name of the file you want to zip.
     tar -a -c -f Compressed.zip FileName.FileExt  
    Compressing one file in CMD

How to Zip Files Using Windows PowerShell

There are several viable ways to create zip files on Windows. One of these is through Windows PowerShell. However, the tar command doesn’t work in Windows PowerShell; we’ll use another command to get the work done.

Here’s how to zip files using Windows PowerShell:

  1. Open the Start Menu, type Windows PowerShell, and choose Run as administrator from the right pane.
  2. In the console, type the following command and press Enter. Ensure to replace file destination and target location with the location of the file and the place where you want the file to be zipped, respectively. Also, replace file name with the name of the file you want to zip and destination name with the destination folder name.
     Compress-Archive -LiteralPath 'file destination\file name' -DestinationPath 'target location\destination name' 
    Zipping command in PowerShell

If you want to zip multiple files, execute the following command. Replace file destination and file destination 1 with the location of the first and second files, respectively. And replace file name and file name 2 with the first and second file names.

 Compress-Archive -LiteralPath 'file destination\file name', 'file destination 1\file name 2 -DestinationPath 'target location\destination name'
Zipping 2 files at once

How to Unzip Files Using Command Prompt

There may be situations where you want to unzip files on your Windows computer. Fortunately, you can do that as well using Command Prompt. Here’s how:

  1. Launch Command Prompt with admin privileges.
  2. Use the cd command to head toward the zip file’s location.
  3. Type the following command and press Enter. Replace ‘Name‘ with the name of the zip file.
     tar -xf Name.zip 
    Unzipping file in CMD

You’ve successfully unzipped the file.

How to Unzip Files Using Windows PowerShell

Windows PowerShell lets you quickly unzip files on your computer. Here’s how to do that:

  1. Open Windows PowerShell with admin rights.
  2. Type the following command and press Enter. Make sure to replace <file destination> and <target location> with the location of the zip file and the place where you want the file to be unzipped, respectively.
     Expand-Archive -LiteralPath <file destination> -DestinationPath <target location> 
    Unzipping file in PowerShell

Save Up Space on Windows 11 by Zipping Your Files

As a Windows user, you will always come across situations where you want to zip or unzip files. However, if you don’t want to use a third-party tool, you can use Command Prompt and Windows PowerShell to quickly zip and unzip files on Windows using the above methods.

Meanwhile, you might be interested in learning a few important Command Prompt commands.

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 8) 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!

  • Windows tweaker на русском для windows 10 скачать бесплатно
  • Windows update error fix windows 7
  • Windows turn off usb port
  • Windows update error 80073712 in windows 7
  • Windows unix подобная или нет