將多個檔案壓縮為多個存檔?

將多個檔案壓縮為多個存檔?

我有一個裝滿 pdf 的資料夾,我厭倦了單獨 Winraring 每個文件。我不想把它們全部放在一個檔案裡。

是否沒有一個命令列可以讓我使用 Winrar 以最佳方法壓縮文件,在製作 .rar 後刪除該文件,然後對下一個文件執行相同的操作?

答案1

是的,WinRAR 安裝資料夾中有一個可執行檔 rar.exe。不帶參數運行它會向您顯示有關其使用的完整幫助。例如,您可以使用 -m5 開關設定最佳壓縮等級。

正如所說,批次/shell 腳本是一種很好的方法,但您可能會發現這個具有類似目標的專案很有趣:http://code.google.com/p/autorar/

答案2

這是我編寫的腳本,用於使用 rar 存檔器(winrar5 格式)單獨壓縮每個檔案。要單獨壓縮資料夾中的所有 *.pdf 文件,您必須將此腳本放入 .bat 檔案中,然後執行它。首先指定檔案所在的起始(根)目錄,然後可以指定在該目錄中尋找和壓縮的副檔名(遞歸搜索,進入根目錄的子目錄)

@echo off

REM -m5 max compression    
REM -md64m dictionary size 64m
REM -s solid
REM -ma5 rar5 format (rar4 - ma4)
REM -y yes to all
REM -t test after packing (if test NOT ok, then files will not be deleted if the -df/-dr specified)
REM -df delete files after successful archivation
REM -ep1 exclude base folder of file from archive
:: %%~nZ - file name extracted from var Z
:: %%~fZ - full path of file+ext from var Z
:: %%~dpZ - disk+path
:: setlocal - use local environment vars
setlocal

:step1
    echo Enter start path where files a located
    set /p rarpath=
    echo.
    :: remove doublequotes from path
    set rarpath=%rarpath:"=%

:check dir exist
    if not exist "%rarpath%" echo   "!!!  [%rarpath%] doesn't exist, please enter correct path  !!!"
    if not exist "%rarpath%" echo.
    if not exist "%rarpath%" goto step1
:::::
:::::
    echo.
    echo Enter which extensions to compress (like *.mp4;*.wmv)
    set /p exten=
    echo.
:::::
:::::
    echo.
    echo Final command: 
    echo for /R "%rarpath%" %%Z in (%exten%) do "%programfiles%\WinRAR\rar.exe" a -ma5 -m5 -s -md64m -t -y -ep1 -df "%%~nZ.rar" "%%~fZ"
    echo.
:::::
:::::
    echo.
    echo Continue? [y/n]
    set /p go=
    if /i %go%==Y goto ok
    if /i %go%==N goto exit

:ok
:: CD to each file's directory, compress file, log output (codepage 866)
set rartime=%time:~0,8%
set rartime=%rartime::=_%
set rartime=%rartime: =%
set rarlog=rar_log_%date%_%rartime%.txt
:: For directories located in current directory
:: for /d %D in (*) do "%programfiles%\winrar\rar.exe" a -ma5 -m5 -s -md64m -t -y -ep1 -df "%D.rar" "%D"

    for /R "%rarpath%" %%Z in (%exten%) do (
        cd /d %%~dpZ
        "%programfiles%\WinRAR\rar.exe" a -ma5 -m5 -s -md64m -t -y -ep1 -df "%%~nZ.rar" "%%~fZ" >> c:\%rarlog% 2>&1
        type c:\%rarlog%
        echo. >> c:\%rarlog%
        echo ----------------------------------------------------------------------------- >> c:\%rarlog%
        echo. >> c:\%rarlog%
    )
    echo.
    echo.
    echo        !!! All Done !!!
    pause
    goto :EOF
    ::EXIT /B 0

:exit
    echo Program terminated
    pause
    goto :EOF

相關內容