2011-09-19 63 views

回答

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! 
) 
+0

如果有9个文件,该脚本完美工作。但是,如果有8个文件,则第三个存档将包含批处理文件本身,并且会有一个包含所有文件和前3个存档的france存档。如果有10个文件,则最后一个文件将被忽略。我使用了'7za a output \!zipfilename! !filelist!'压缩文件。我做错了什么? – WTFIsGoingOn

+0

你的8个文件测试用例是正确的。它也采用批处理文件,因为for循环正在查找所有文件。我已经修改了上面的脚本来过滤批处理文件,使其在循环中进行压缩时包含在文件列表中。对于10个文件的情况,我想你可能忘了在最后的if条件块(在最后的if块中“rem your ...”行)忘记做zip。 – Arun

相关问题