如何排除压缩主文件中的子文件?

时间:2015-09-02 03:44:06

标签: windows batch-file cmd batch-processing

 @ECHO OFF
 SET hr=%time:~0,2%
 IF %hr% lss 10 SET hr=0%hr:~1,1%


 Set TODAY=%date:~4,2%-%date:~7,2%-%date:~10,4%-%hr%%time:~3,2%%time:~6,2%%time:~9,2%
 ECHO.


 ECHO.

这是从压缩

中排除“C:\ Users \ Downloads \ back \ temp”的文件夹
 7za.exe a -tzip "C:\Users\Desktop\Downloadbak-%TODAY%.zip" "C:\Users\Downloads\back*" -mx5
 ECHO.

 PAUSE

1 个答案:

答案 0 :(得分:2)

  1. 将当前文件夹更改为基本文件夹并使用-x开关:

    pushd C:\Users\Downloads\back
    7za.exe a -tzip -mx5 -x!temp -x!exclude2 "C:\Users\Desktop\Downloadbak-%TODAY%.zip" *
    popd
    
  2. 或管道dir输出到find以排除文件夹名称并将结果用作7zip的列表文件:

    pushd C:\Users\Downloads\back
    dir /b /a | findstr /i /v /r /c:"^temp$" >"%temp%\listfile"
    7za.exe a -tzip -mx5 "C:\Users\Desktop\Downloadbak-%TODAY%.zip" @"%temp%\listfile"
    del "%temp%\listfile"
    popd