标题: [文件操作] 批处理分别调用7-Zip和WinRAR把文件批量分组压缩成zip格式 [打印本页]
作者: Batcher 时间: 2015-3-25 10:49 标题: 批处理分别调用7-Zip和WinRAR把文件批量分组压缩成zip格式
【方法1】7-Zip- @echo off
- setlocal enabledelayedexpansion
- REM 设置多少个文件压缩成同一个包
- set "GroupSize=3"
- REM 假设7-Zip安装在以下目录
- set "SevenZip=C:\Program Files\7-Zip\7z.exe"
-
- set "ZipCounter=1"
- set "FileCounter=0"
- REM 假设需要压缩的是当前目录下的txt文件
- for /f "delims=" %%i in ('dir /b /a-d *.txt') do (
- "%SevenZip%" u !ZipCounter!.zip "%%i"
- set /a FileCounter+=1
- if !FileCounter! equ %GroupSize% (
- set /a ZipCounter+=1
- set "FileCounter=0"
- )
- )
复制代码
【方法2】WinRAR- @echo off
- setlocal enabledelayedexpansion
- REM 设置多少个文件压缩成同一个包
- set "GroupSize=3"
- REM 假设WinRAR安装在以下目录
- set "WinRAR=C:\Program Files\WinRAR\WinRAR.exe"
-
- set "ZipCounter=1"
- set "FileCounter=0"
- REM 假设需要压缩的是当前目录下的txt文件
- for /f "delims=" %%i in ('dir /b /a-d *.txt') do (
- "%WinRAR%" a -ibck !ZipCounter!.zip "%%i"
- set /a FileCounter+=1
- if !FileCounter! equ %GroupSize% (
- set /a ZipCounter+=1
- set "FileCounter=0"
- )
- )
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |