2011-09-19 47 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

相關問題