Ele*_*hoy 126 windows compression command-line-interface
由于 Windows 资源管理器(至少从 Windows XP 开始)对 ZIP 文件有一些基本支持,似乎应该有一个等效的命令行,但我似乎找不到任何迹象。
Windows(XP、Vista、7、8、2003、2008、2013)是否附带内置命令行压缩工具,还是我需要坚持使用第三方工具?
Bry*_*yan 56
它没有内置在 Windows 中,但它在资源工具包工具中作为COMPRESS,
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.
Run Code Online (Sandbox Code Playgroud)
例子:
COMPRESS temp.txt compressed.txt
COMPRESS -R *.*
COMPRESS -R *.exe *.dll compressed_dir
Run Code Online (Sandbox Code Playgroud)
Chr*_*ris 25
不是我所知道的。就第三方工具而言,7zip 有一个非常漂亮的命令行界面,并且二进制文件可以与您的应用程序一起分发到应用程序目录中,因此您不必依赖于提前安装它。
MDM*_*rra 15
.Net 4.5 内置了此功能,PowerShell 可以利用它。您需要使用 Server 2012、Windows 8 或手动安装 .Net 4.5。
[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)
Run Code Online (Sandbox Code Playgroud)
Kyl*_*Mit 10
根据Windows 10 版本 1803 中命令行的新增功能,Windows 现在附带tar.exe内置命令,您可以像这样使用它:
C:\temp> tar.exe -xf files.zip
Run Code Online (Sandbox Code Playgroud)
小智 7
为此,有一个简单的 PowerShell 命令。(PowerShell v5.0+)
压缩:
Compress-Archive -LiteralPath 'C:\mypath\testfile.txt' -DestinationPath "C:\mypath\Test.zip"
Run Code Online (Sandbox Code Playgroud)
解压缩:
Expand-Archive -LiteralPath "C:\mypath\Test.Zip" -DestinationPath "C:\mypath" -Force
Run Code Online (Sandbox Code Playgroud)
资料来源:
特别感谢@Ramhound