Zip files are a convenient way to package and share groups of files. In this blog, we will show you how to zip and unzip files through PowerShell and the Command Prompt in Windows.
To zip files using PowerShell, follow these steps:
- Open PowerShell as an administrator by right-clicking on the PowerShell icon and selecting “Run as administrator”.
- Navigate to the folder that contains the files you want to zip. You can use the
cd
command to change directories. For example:
cd C:\Users\Username\Documents\MyFiles
- Run the following command to create a zip file containing all the files in the current directory:
Compress-Archive -Path * -DestinationPath MyZipFile.zip
This will create a new zip file called MyZipFile.zip
in the current directory. You can specify a different path for the zip file by replacing MyZipFile.zip
with the desired path and filename.
- To include only certain files in the zip file, you can specify their names or patterns. For example:
Compress-Archive -Path *.txt, *.docx -DestinationPath MyZipFile.zip
This will create a zip file containing only the .txt
and .docx
files in the current directory.
To unzip a zip file using PowerShell, use the following command:
Expand-Archive -Path MyZipFile.zip -DestinationPath C:\ExtractHere
This will extract the contents of the MyZipFile.zip
file to the C:\ExtractHere
directory.
You can also use the Command Prompt to zip and unzip files. To do this, follow these steps:
- Open the Command Prompt by typing “cmd” in the search bar and pressing Enter.
- Navigate to the folder that contains the files you want to zip. You can use the
cd
command to change directories. For example:
cd C:\Users\Username\Documents\MyFiles
- To create a zip file, run the following command:
zip MyZipFile.zip *
This will create a new zip file called MyZipFile.zip
in the current directory. You can specify a different path for the zip file by replacing MyZipFile.zip
with the desired path and filename.
- To include only certain files in the zip file, you can specify their names or patterns. For example:
zip MyZipFile.zip *.txt *.docx
This will create a zip file containing only the .txt
and .docx
files in the current directory.
To unzip a zip file using the Command Prompt, use the following command:
unzip MyZipFile.zip -d C:\ExtractHere
This will extract the contents of the MyZipFile.zip
file to the C:\ExtractHere
directory.