在Windows中,你可以压缩一些文件

右键单击→发送到→压缩(压缩)文件夹

双击.zip文件解压缩并解压缩文件。

是否有一种方法可以从脚本(.bat文件)应用这些功能,而不需要安装任何第三方软件?


当前回答

正如@Noam Manos所回答的,我们可以通过在.bashrc文件中使用别名来改进压缩:

别名zip=“jar -cMf”

然后命令(在bash终端中)将是

邮编目标.zip目录1 目录2

注意:你应该安装java和git bash,并在windows中进行安装。

其他回答

更新的windows版本包括tar.exe。 Tar.exe可用于CMD或Windows批处理文件中。

//Compress a folder:
tar -caf aa.zip c:\aa

如果你安装了Java,你可以使用jar命令压缩成ZIP文件:

jar -cMf targetArchive.zip sourceDirectory

创建一个新的归档文件。 M =指定清单文件不应添加到存档。 f =目标文件名。

为了扩展Steven Penny的PowerShell解决方案,你可以通过调用PowerShell .exe将其合并到一个批处理文件中,就像这样:

powershell.exe -nologo -noprofile -command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('foo.zip', 'bar'); }"

正如Ivan Shilo所说,这在PowerShell 2中行不通,它需要PowerShell 3或更高版本和. net Framework 4。

它并不是ZIP文件,但使用Windows工具压缩文件的唯一方法是:

makecab <source> <dest>.cab

减压:

expand <source>.cab <dest>

高级示例(来自ss64.com):

Create a self extracting archive containing movie.mov:
C:\> makecab movie.mov "temp.cab"
C:\> copy /b "%windir%\system32\extrac32.exe"+"temp.cab" "movie.exe"
C:\> del /q /f "temp.cab"

更多信息:makecab,扩展,makecab高级用法

这个对我来说很管用(在2021年):

tar -xf test.zip

这将解压缩当前目录中的测试。