bat 壓縮檔案

  • 1025
  • 0

摘要:bat 壓縮檔案

程式寫完,用 VS發行通常會因為沒有權限或其他雜七雜八的原因只能選檔案系統,然後壓縮,上傳,再到別台機器解壓縮…瑣碎,沒什麼難度的工作。

寫了簡單的批次檔做這事兒,

壓縮:

set FileFullPath=%1

set backtime=%date:~0,4%%date:~5,2%%date:~8,2%_%time:~0,2%%time:~3,2%%time:~6,2%
set compress="C:\program Files\7-zip\7z"

if "%FileFullPath%"=="D:\patch1Foler" goto patch1
if "%FileFullPath%"=="D:\patch2Foler" goto patch2

exit

:patch1
set backupPathFrom="D:\patch1Foler\*"
set backupPathTo="D:\"%backtime%"_patch1.zip"
goto exec

:patch2
set backupPathFrom="D:\patch2Foler\*"
set backupPathTo="D:\"%backtime%"_patch2.zip"
goto exec

:exec
%compress% a -r -tzip %backupPathTo% %backupPathFrom%
%compress% d %backupPathTo% "/bin/*.pdb" -r

rem pause

解壓縮:

set FileFullPath=%1

set PatchName=%FileFullPath:~-9% rem 截 compress的 patch字串
set compress="C:\program Files\7-zip\7z"

if "%PatchName%"=="patch1.zip" goto patch1
if "%PatchName%"=="patch2.zip" goto patch2

:patch1
set Dest="D:\patch1\"
set Backup="D:\patch1\backup\"
goto exec

:patch2
set Dest="D:\patch2\"
set Backup="D:\patch2\backup\"
goto exec

:exec
%compress% -y x "%FileFullPath%" -o%Dest%
move /-y "%FileFullPath%" %Backup%

rem pause

存成 .bat檔,要用的時候把目錄拉到 .bat檔上就行了。喔,對了,壓縮的程式是用 7zip。