7-zip 命令行
我正在创建一个备份实用程序,用于压缩文本文件中列出的所有文件。我使用 MS ACCESS 作为前端,并使用 7-Zip 进行压缩。这些是我正在使用的命令:
7zG.exe a c:\Backup\backup.zip
@c:\temp\tmpFileList.txt
所有文件都被压缩,没有它们的路径。有没有办法在 zip 文件中包含每个文件的路径?然后,当解压 backup.zip
时,文件将恢复到其原始文件夹结构。
谢谢
I'm creating a backup utility that zips all the files listed in a text file. I am using MS ACCESS as my front-end and 7-Zip for compression. These are the commands I am using:
7zG.exe a c:\Backup\backup.zip
@c:\temp\tmpFileList.txt
All the files are compressed without their path. Is there a way to include the path for each file in the zip file? Then when backup.zip
is extracted the files would be restored to their original folder structure.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
在 这个 7-zip 论坛帖子中,许多人表示为了表达对这一功能的渴望,7-zip 的开发人员 Igor 指出了常见问题解答,标题为“我怎样才能在存档中存储文件的完整路径?”以获得类似的结果。
简而言之:
C:\
上的文件,一个列表用于D:\
等),cd /d C:\
)C:\Foo\Bar
变为Foo\Bar
)7z a archive.7z @filelist
In this 7-zip forum thread, in which many people express their desire for this feature, 7-zip's developer Igor points to the FAQ question titled "How can I store full path of file in archive?" to achieve a similar outcome.
In short:
C:\
, one forD:\
, etc)cd /d C:\
)C:\Foo\Bar
becomesFoo\Bar
)7z a archive.7z @filelist
as before with this new file list7-Zip 的命令行程序是 7z 或 7za。这是关于可用选项的有用的帖子。 -r(递归)选项存储路径。
The command-line program for 7-Zip is 7z or 7za. Here's a helpful post on the options available. The -r (recurse) option stores paths.
我没有研究过这一点,但我想说的是,他们在便携式设备中放弃了命令行支持。人们不在便携式应用程序中执行太多命令行操作的原因是操作系统(在您的情况下是 Windows)要求将可执行文件添加到 %path% 包含列表中。
如果不满足该要求,则使用命令行实用程序是相当乏味的。
7z -a .
将是
d:\portable\z7\z7 -ac:\to\archive\folder*.*
为所有内容键入该内容就是为什么 GUI 对于便携式应用程序之类的东西有意义(该应用程序)可以记住它自己的位置并为您处理这些内容,如果您无法运行它,您知道它没有附加。
如果您确实希望便携式应用程序包含该应用程序,那么您始终可以安装完整版本并将所需的 7z.exe 取出并将其放入便携式文件夹中,确保它与所需的 dll 一起。
确保外壳已连接后,您必须在敲击外壳时设置路径。
http://www.redfernplace.com/software-projects/patheditor/ --如果您有大量 20+ 的路径信息难以阅读,那么一个好的路径编辑器(向下)很有用。
http://www.softpedia.com/get/System/System -Miscellaneous/Path-Editor.shtml -- 路径编辑器的alternet源代码
不建议修改临时“便携式”驱动器的系统路径,尽管手动执行此操作:
set path=%path%;"d:\便携式\z7\";
当您运行 dos cmd.exe 或 http://sourceforge.net/p/conemu/home/ Home/
其他答案可以更好地解决其他问题,我不会尝试..
http://www.codejacked.com/zip-up-files-from-the-command-line/ -- z7 和 z7a 命令行使用的良好参考。
PS:对死灵感到抱歉,但我认为它需要一个更直接的答案来解释原因(即使这只是推测)。
I've not looked into this but shooting from the hip I'd say that they dropped command line support in the portable. The reason people don't do much command line stuff in portable applications is that the OS (windows in your case) requires that executables be added to the %path% inclusion list.
If that requirement is not met using command line utilities is rather tedious.
7z -a .
would be
d:\portable\z7\z7 -a c:\to\archive\folder*.*
Typing that out for everything is why GUI's make sense with things like portable apps it (the app) can remember it's own location and handle that stuff for you and if you can't run it you know it's not attached.
If you really want the portable app to contain that though you can always install the full version and pull the required 7z.exe out and put it into the portable folder making sure it's in with the required dll's.
You'll have to set your path when you hit the shell after making sure it's attached.
http://www.redfernplace.com/software-projects/patheditor/ -- a good path editor (down) usefull if you have lots of path information 20+ get's hard to read.
http://www.softpedia.com/get/System/System-Miscellaneous/Path-Editor.shtml -- alternet source for path editor
It's not advisable to modify your system path for temproary "portable" drives though manualy do that by:
set path=%path%;"d:\portable\z7\";
when you run dos cmd.exe or http://sourceforge.net/p/conemu/home/Home/
The other answers address other problems better I'm not going to try..
http://www.codejacked.com/zip-up-files-from-the-command-line/ -- good reference for command line usage of z7 and z7a.
PS: sorry for the necro but I figured it needed a more direct answer to why (even if it's just speculative).
试试这个。它对我有用。
7z.exe ad:\newFileName.7z "d:\ExistingFile.txt"
打开 cmd,如果您已经安装了 7zip 应用程序,请尝试此操作。
在命令提示符下,它将类似于 c:\programs and files\7zip\7z.exe ad:\newFileName.7z "d:\ExistingFile.txt"
try this one. it worked for me.
7z.exe a d:\newFileName.7z "d:\ExistingFile.txt"
open cmd and if you have installed 7zip app then try this.
on command prompt it will like c:\programs and files\7zip\7z.exe a d:\newFileName.7z "d:\ExistingFile.txt"
从 7-zip 版本 9.25 alpha 开始,有一个新的
-spf
开关,可用于存储完整的文件路径,包括存档的驱动器号。现在应该工作得很好。
Since 7-zip version 9.25 alpha there is a new
-spf
switch that can be used to store the full file paths including drive letter to the archive.should be working just fine now.
7-Zip 需要列表文件中的相对路径,否则它将仅存储文件名,从而导致重复文件名错误。
假设您的列表包含完整路径名:
如果您的列表文件具有相对于另一个文件夹的路径,则您应该从该文件夹运行 7Z。
更新:我从上面的另一篇文章中注意到,新的 7-Zip 有一个 -spf 选项,不需要上述步骤。尚未测试,但我的步骤适用于没有此选项的早期版本。
7-Zip wants relative paths in the list file otherwise it will store only the filenames, causing duplicate file name error.
Assuming that your list contains full path names:
If your list file has paths relative to another folder, you should be running 7Z from that folder.
Update: I noticed from another post above that the new 7-Zip has an -spf option that doesn't require the above steps. Not tested it yet but my steps are for earlier versions that do not have this option.
我创建了以下批处理文件,以利用 7-Zip 将每个子文件夹压缩到其自己的 zip 文件中,并保留文件结构。由于这有效地演示了命令行,我认为它可能会帮助其他人将其发布在这里。
I created the following batch file to utilize 7-Zip to zip up every subfolder into its own zip file, preserving the file structure. Since this demonstrates the commandline effectively, I thought it might help someone else to post it here.
使用选项
x
代替选项a
,这将创建目录,但仅用于提取,而不是压缩。Instead of the option
a
use optionx
, this will create the directories but only for extraction, not compression.