How to compress multiple files into 3 files per archive with windows batch file?
I have 100 files that look like this:
001.txt
002.txt
003.txt
004.txt
.....
100.txt
I want to compress them like this:
001.txt
002.txt ----> archive01.7z
003.txt
---------
004.txt
005.txt ----> archive02.7z
006.txt
Ho开发者_运维知识库w can I achieve this with windows batch file?Thanks in advance:D
@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!
)
精彩评论