Read password from txt file and auto extract RAR file
- 取得Part1 RAR檔名
- 取得解壓密碼檔名
- 讀取解壓密碼 (txt編碼為ANSI)
- 執行解壓縮
@ECHO OFF
REM 取得Part1 RAR檔名
FOR /f "delims=" %%a in ('DIR *.rar /oe /b') DO (
SET fisrtFileName=%%a
GOTO getPasswordFileName
)
:getPasswordFileName
REM 取得解壓密碼檔名
FOR /f "delims=" %%a in ('DIR *.txt /oe /b') DO (
SET passwordFileName=%%a
GOTO getPassword
)
:getPassword
REM 讀取解壓縮密碼
REM pw.txt編碼為ANSI
FOR /f "usebackq tokens=1" %%i in ("%passwordFileName%") DO (
SET rarPassword=%%i
GOTO extractFile
)
:extractFile
ECHO RarFileName:%fisrtFileName%
ECHO PwFileName:%passwordFileName%
ECHO Pw:%rarPassword:&=^&%
REM 執行解壓縮
"C:\Program Files\WinRAR\Rar.exe" -p"%rarPassword%" x %fisrtFileName%
FOR /f "delims=" %%a in ('DIR *.url /oe /b') DO (
SET urlFileName=%%a
GOTO renameJPG
)
:renameJPG
REM 重新命名封面
REN *.jpg %urlFileName:.url=%.jpg
PAUSE