windows 命令提示符 zip/compress 目录

Posted

技术标签:

【中文标题】windows 命令提示符 zip/compress 目录【英文标题】:windows command promt zip/compress directory 【发布时间】:2010-07-16 15:21:21 【问题描述】:

是否可以在 cmd.exe 的单个文件中压缩/归档一个目录及其所有子目录和文件?我知道有很多实用程序可用,但我只需要使用 windows 默认实用程序执行操作。我正在运行 Windows Server 2003。

【问题讨论】:

我知道 makecab 但我认为它不会保留目录树 ....如果我错了请纠正我 你试过我的(很老的)答案了吗? 检查这个:***.com/questions/28043589/… 【参考方案1】:

虽然旧的 makecab 不存储真正的目录结构,但如果您确实需要,您可以命令每个文件的输出目录。该过程比使用现代实用程序更麻烦,但可以完成。

为此,您应该创建一个 .ddf 文件。

旧版 makecab 的手册已被 MS 从网上删除。我找到了一个副本here。

在 makecab 手册的第 33 页中,您会发现:

DestinationDir=pathPath prefix to store in cabinet file for each file in the cabinet.Default: .Set DestinationDir= ; Default is no path prefix

路径is concatenated with a path separator (“\”) and the target file name onFile Copy Commands to produce the file name that is stored in cabinet file. EXTRACT.EXE will use this file name as the default name when the file is extracted.

Examples:  
.Set DestinationDir=SYSTEM  ; Following files get SYSTEM prefix      
bin\ARIAL.TTF           ; Name in cabinet is SYSTEM\ARIAL.TTF  
.Set DestinationDir=        ; No prefix  
bin\ARIAL.TTF           ; Name in cabinet is ARIAL.TTF

HTH!

【讨论】:

【参考方案2】:

您可以做的真的很少,因为没有命令行压缩作为 Windows 的一部分作为标准。

我能想到的最接近的方法是使用备份程序NTBackup。

如果有任何方法可以安装实用程序,我强烈推荐7zip,我在编写脚本方面有很好的经验。

【讨论】:

我是 Windows 管理的新手。你能帮我快速的语法来“压缩”(虽然我知道它不会压缩/归档)一个目录,它的所有子目录都在一个文件中吗?在 linux 上我只使用 tar -cvzf file.tar 目录

以上是关于windows 命令提示符 zip/compress 目录的主要内容,如果未能解决你的问题,请参考以下文章

windows怎么打开命令提示符

windows命令提示符中如何输入多行命令

window power shell与命令提示符哪个好用

以管理员的身份运行命令提示符显示“windows 无法访问指定设备,路径或

windows命令行窗口怎么打开

如何用Windows PowerShell替换命令提示符