如何使用Windows批处理文件将每个存档的多个文件压缩为3个文件?

时间:2011-09-19 14:41:16

标签: batch-file compression 7zip

我有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

如何使用Windows批处理文件实现此目的?提前感谢:D

1 个答案:

答案 0 :(得分:1)

@echo off
setlocal enabledelayedexpansion
rem initialize all variables
set counter=1
set groupnumber=1
rem change groupcount value if you want a different number of files per zip
set groupcount=3
set zipfilenamePrefix=archive
rem start looping over...
for %%f in (*) do (
    if not "%%f"=="%~nx0" (
        set fileList=!fileList! %%f
        set /a reminder=!counter!%%!groupcount!
        if !reminder! equ 0 (
            set zipfilename=archive!groupnumber!.tz
            echo Zipping files: !fileList! into !zipfilename!
            rem your zipping utility goes here: input = !fileList! and output = !zipfilename!
            set /a groupnumber=!groupnumber!+1
            set fileList=
        )
        set /a counter=counter+1
    )
)
rem there could be some left over files - last group may be less than 3 files
if !reminder! equ 0 (
    set zipfilename=archive!groupnumber!.tz
    echo Zipping into files: !fileList! !zipfilename!
    rem your zipping utility goes here: input = !fileList! and output = !zipfilename!
)