@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=%~dp0
::進入目標路徑
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"
::進行壓縮
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