我有 100 个如下所示的文件:
001.txt
002.txt
003.txt
004.txt
.....
100.txt
我想像这样压缩它们:
001.txt
002.txt ----> archive01.7z
003.txt
---------
004.txt
005.txt ----> archive02.7z
006.txt
如何使用 7-Zip 实现这一点?
答案1
嗯,这取决于...如果你在 Windows 中运行 Linux 或类似 Linux 的 shell(例如 cygwin),那么它是一个用 bash 或你最喜欢的语言(如 python 或 perl)编写的简单程序。
这里有一些(未经测试;))伪代码(有点接近 bash,但没有很多额外需要的语法)。
I=0 ##File counter
J=1 ##Archive counter
## the following while strategy will work in most languages as long as you don't
## have thousands of files - if you do, read them in 1 at a time in the loop
while FILE in <list-of-files-to zip> ## Loop across all files like *.txt
do
if I mod 3 == 0 ## If we're at the start of a new archive
then
COMMAND="7z -a archive"J".7z " FILE " " ##Start a new command line for archive "J"
J++
else
COMMAND=COMMAND FILE ##append the next file name to the command string
if I mod 3 == 2 ## if the desired number of files are appended
then
append COMMAND string to a script file to run later
or run it directly right here
COMMAND="" ## clear the COMMAND string
fi
fi
I++
done
## Handle left over files
I-- ## Loop increments I after last file
if I mod 3 != 2
then
append COMMAND string to a script file to run later
or run it directly right here
fi
您可以将“3”更改为变量(SIZE),以构建包含不同文件数量的档案。如果您这样做,那么“2”将变成 SIZE-1。
高血压