Sejak Windows Explorer (setidaknya sejak Windows XP) memiliki beberapa dasar dukungan untuk file ZIP, sepertinya harus ada baris perintah yang setara, tapi aku bisa't tampaknya menemukan ada tanda-tanda dari satu.
Apakah Windows (XP, Vista, 7, 8, 2003, 2008, 2013) kapal dengan built-in command-line kantong alat, atau apakah saya perlu untuk tetap dengan alat pihak ketiga?
It's tidak dibangun ke dalam Windows, tapi itu's di Resource Kit Tools sebagai KOMPRES
,
C:\>compress /?
Syntax:
COMPRESS [-R] [-D] [-S] [ -Z | -ZX ] Source Destination
COMPRESS -R [-D] [-S] [ -Z | -ZX ] Source [Destination]
Description:
Compresses one or more files.
Parameter List:
-R Rename compressed files.
-D Update compressed files only if out of date.
-S Suppress copyright information.
-ZX LZX compression. This is default compression.
-Z MS-ZIP compression.
Source Source file specification. Wildcards may be
used.
Destination Destination file | path specification.
Destination may be a directory. If Source is
multiple files and -r is not specified,
Destination must be a directory.
Contoh:
COMPRESS temp.txt compressed.txt
COMPRESS -R *.*
COMPRESS -R *.exe *.dll compressed_dir
Bukan berarti saya'm sadar. Sejauh alat pihak ketiga berjalan, 7zip memiliki cukup bagus antarmuka baris perintah dan biner dapat didistribusikan dengan aplikasi anda di app's direktori, sehingga anda don't harus bergantung pada itu dipasang di depan waktu.
Powershell tidak. Lihat:
Kompres File dengan Windows PowerShell kemudian paket Windows Vista Sidebar Gadget
.Net 4.5 ini memiliki fungsi built-in, dan dapat dimanfaatkan oleh PowerShell. Anda'll perlu berada di Server 2012, Windows 8, atau memiliki .Net 4.5 diinstal secara manual.
[Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem")
$Compression = [System.IO.Compression.CompressionLevel]::Optimal
$IncludeBaseDirectory = $false
$Source = "C:\Path\To\Source"
$Destination = "C:\CoolPowerShellZipFile.zip"
[System.IO.Compression.ZipFile]::CreateFromDirectory($Source,$Destination,$Compression,$IncludeBaseDirectory)
Solusi lain yang ditemukan pada superuser situs menggunakan windows asli com objek .bat file:
Ada yang single, sederhana perintah PowerShell untuk ini. (PowerShell v5.0+)
Untuk zip:
Compress-Archive -LiteralPath 'C:\mypath\testfile.txt' -DestinationPath "C:\mypath\Test.zip"
Untuk unzip:
Expand-Archive -LiteralPath "C:\mypath\Test.Zip" -DestinationPath "C:\mypath" -Force
Sumber:
Terima kasih khusus untuk @Ramhound