Zip in Windows 10 Pro batch file
The Windows 10 Pro command prompt does not have a command to compress zip.
However, PowerShell has a Compress-Archive command, so you can call PowerShell’s ps1 file from a batch file to compress it.
The file layout configuration is as follows.
Location |
---|
c:\tmp\a.bat |
c:\tmp\a.ps1 |
The folder to be compressed is assumed to be the same as the one under the folder.
Folder you want to compress | Compressed Folder Name |
---|---|
c:\temp\common|common.zip |
a.bat
@echo off powershell -ExecutionPolicy Unrestricted .\a.ps1 exit /b
a.ps1
Compress-Archive -Path C:\temp\common\ -DestinationPath C:\temp\common.zip
Execute this file.
I was able to run the batch file and zip it.
Use the powershell command
Zip the file using the powershell command in a batch file without creating a ps1 file.
a.bat
@echo off powershell compress-archive common common.zip
Execute zip command via wsl
If you have a Linux environment with wsl, you can use the zip command via the wsl command.
Install the zip command via wsl sudo apt install zip.
Compress the file under c:\tmp\ to a.zip.
c:\tmp>wsl zip a -r9 .
コメント