通过批处理文件bat 编辑dos命令 实现7z 批量压缩指定文件夹下内容

@echo off

echo -------------Start to zip files by 7z------------------

:start

::输入目标目录
echo please input the root directory which you want zip
set /p target_directory=

::判断非法输入
if "%target_directory%"=="" goto :start
if exist %target_directory% if not exist %target_directory%\nul echo INVALID INPUT: %target_directory% &goto:start


::记录执行文件路径
set current_directary=%cd%
::进入目标路径
cd %target_directory%
::如果是其他区
if "%cd%"=="%current_directary%" cd /d %target_directory%


::设置参数(记得修改为自己的参数)
set "exe_dir=D:\Program Files (x86)\7-Zip\7z.exe"
set "my_secret=123456"
set "info_log=%current_directary%\7z_INFO.log" 
set "error_log=%current_directary%\7z_ERROR.log" 

 

::以下注释可用于调试
::echo %target_directory%
::echo %current_directary%
::pause
::goto start
 

::进行压缩
for %%X in (*) do "%exe_dir%" a "%%X.7z" -p%my_secret% -mhe -mx=5  "%%X" 1>>%info_log% 2>>%error_log%
for /d %%X in (*) do "%exe_dir%" a "%%X.7z" -p%my_secret% -mhe -mx=5 "%%X" 1>>%info_log% 2>>%error_log%


::提示压缩完毕
mshta vbscript:createobject("sapi.spvoice").speak("zip files have finished")(window.close)
mshta vbscript:msgbox("zip files have finished",1,"My 7z")(window.close)


goto start

你可能感兴趣的:(windows,dos,7zip)