Board logo

标题: [文件操作] 批处理分别调用7-Zip和WinRAR把文件批量分组压缩成zip格式 [打印本页]

作者: Batcher    时间: 2015-3-25 10:49     标题: 批处理分别调用7-Zip和WinRAR把文件批量分组压缩成zip格式

【方法1】7-Zip
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. REM 设置多少个文件压缩成同一个包
  4. set "GroupSize=3"
  5. REM 假设7-Zip安装在以下目录
  6. set "SevenZip=C:\Program Files\7-Zip\7z.exe"
  7. set "ZipCounter=1"
  8. set "FileCounter=0"
  9. REM 假设需要压缩的是当前目录下的txt文件
  10. for /f "delims=" %%i in ('dir /b /a-d *.txt') do (
  11.     "%SevenZip%" u !ZipCounter!.zip "%%i"
  12.     set /a FileCounter+=1
  13.     if !FileCounter! equ %GroupSize% (
  14.         set /a ZipCounter+=1
  15.         set "FileCounter=0"
  16.     )
  17. )
复制代码
【方法2】WinRAR
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. REM 设置多少个文件压缩成同一个包
  4. set "GroupSize=3"
  5. REM 假设WinRAR安装在以下目录
  6. set "WinRAR=C:\Program Files\WinRAR\WinRAR.exe"
  7. set "ZipCounter=1"
  8. set "FileCounter=0"
  9. REM 假设需要压缩的是当前目录下的txt文件
  10. for /f "delims=" %%i in ('dir /b /a-d *.txt') do (
  11.     "%WinRAR%" a -ibck !ZipCounter!.zip "%%i"
  12.     set /a FileCounter+=1
  13.     if !FileCounter! equ %GroupSize% (
  14.         set /a ZipCounter+=1
  15.         set "FileCounter=0"
  16.     )
  17. )
复制代码





欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2