Windows 是否有用于命令行的内置 ZIP 命令?

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)

  • 这与可用的 ZIP 客户端相去甚远。您无法压缩文件夹,并且似乎无法将压缩文件添加到现有存档中。避免。 (8认同)
  • Compress 实际上不是 ZIP 客户端。它会创建您曾经在 MS-DOS 和 Windows 3.11/95 安装盘上找到的那些文件。例如 WINSOCK.DL_ 扩展为 WINSOCK.DLL。您可以使用 `expand` 解压缩文件。 (4认同)

Chr*_*ris 25

不是我所知道的。就第三方工具而言,7zip 有一个非常漂亮的命令行界面,并且二进制文件可以与您的应用程序一起分发到应用程序目录中,因此您不必依赖于提前安装它。

  • 就像我说的,你不必安装它。将二进制文件复制到某个文件夹并从那里运行它。 (5认同)
  • 好吧,你我不考虑安装。但是,如果您知道我的意思,那么有问题的 IT 经理会这样做。:) (2认同)
  • 哈,所以从远程网络共享运行 7zip 二进制文件:) (2认同)

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

更新 - 内部版本 1803(2018 年 3 月)

根据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


小智 6

在超级用户站点上找到的另一个解决方案使用 .bat 文件中的 windows 本机 com 对象:

您能否仅使用 Windows 的内置压缩文件功能从命令提示符压缩文件?