使用 7-zip 批处理:先将最小文件压缩到最大文件

发布于 2024-10-22 20:57:44 字数 329 浏览 7 评论 0原文

我有一个 .bat 文件,它运行 7-zip 来压缩目录中的所有文件。文件大小从 1mb 到 500mb 不等,共有 10 个文件。每 15 分钟,计划的备份程序就会覆盖 10 个文件中的 5 个。这 5 个文件通常是最小的且压缩速度最快,但 7-zip 首先从最大的文件开始,因此在 15 分钟内丢失了这 5 个文件。如何让 7-zip 首先从最小的文件开始。任何帮助将不胜感激。

c:
cd "\Program Files\7-Zip"
7z a C:\WEBDATA C:\FILE1.BAK C:\FILE2.BAK C:\FILE3 C:\FILE4 C:\FILE5 etc...

I have a .bat file that runs 7-zip to compress all files in a directory. The files range in size from 1mb to 500mb and there are 10 files. Every 15 mins a scheduled backup program overwrites 5 of the 10 files. Those 5 files are usually the smallest and the quickest to compress, but 7-zip starts with the largest file first thus missing the 5 files within the 15 minutes. How do I get 7-zip to start with the smallest file first. Any help would be much appreciated.

c:
cd "\Program Files\7-Zip"
7z a C:\WEBDATA C:\FILE1.BAK C:\FILE2.BAK C:\FILE3 C:\FILE4 C:\FILE5 etc...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼泪都笑了 2024-10-29 20:57:44

如果所有文件都位于同一目录中,则可以使用 dir 命令的排序功能一次将一个文件添加到存档中。

例如,如果要备份的文件位于名为“files”的子目录中:

for /f %%N in ('"dir /A-D /O:S /B files"') do (
   7z a backup.7z files/%%N
)

根据您的描述,这应该足够了,但如果文件位于不同的位置,您可能需要更高级。我自己还没有尝试过,但我希望您可以循环遍历目录列表,将每个大小/文件名写入临时文件,然后对该文件使用 sort 命令。

If all of the files are in the same directory, you can use the sort feature of the dir command to add files to the archive one at a time.

For example, if the files to back up are in a subdirectory called 'files':

for /f %%N in ('"dir /A-D /O:S /B files"') do (
   7z a backup.7z files/%%N
)

Based on your description this should be sufficient, but if the files are in various locations you may need to get fancier. I haven't tried it myself, but I would expect you could loop through a list of directories, writing each size / filename to a temporary file, then using the sort command on that file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文