使用批处理的密码和加密 RAR 文件

RAR files with password and enryption using batch

我在驱动器 d: 中有四个文件夹,每个文件夹中都有一个名为 file.txt 的文件。如果我使用下面的批处理脚本,所有四个 txt 文件都会被压缩,并且它们在没有密码的情况下被压缩,并且没有在其中隐藏文件名。我只想压缩Folder 4中的文件。我的密码是 MYPass 我压缩的 bz2 是 FileCompressed.bz2

我只需要压缩文件夹 4 中的文件,假设对所有查询都是“是”,不显示消息,最大压缩,带密码,压缩后删除 File.txt(在文件夹 4 上),带加密文件的名称。我用了“rar -?”在 windows 提示符下,但我仍然不知道如何获得我需要的结果。有人可以帮忙吗?

d:
\文件夹 1\file.txt
\文件夹 2\file.txt
\文件夹 3\file.txt
\文件夹4\file.txt

@echo off
rar a -hpMyPass -m5 -y -df "d:\Folder 4\FileCompressed.bz2" "d:\Folder 4\File.txt"

试试这个示例代码:

@echo off
Title Zip Files with rar.exe in command line
color 0A & Mode 75,10
Set "Folder2Compress=D:\Folder 4"
If Not exist "%Folder2Compress%\" MD "%Folder2Compress%\"
(echo This is a test to see if the compression with encryption in winrar works or not)>"%Folder2Compress%\File.txt"
Set "CompressedFolder=%~dp0FileCompressed.bz2"
set "RAR_Password=MyPass"
Set "Log=%~dpn0_Log.txt"

Set "strProgramFiles=%ProgramFiles%"
if exist "%ProgramFiles(x86)%" (
    set "strProgramFiles=%ProgramFiles(x86)%"
) else (
    set "strProgramFiles=%ProgramFiles%"
)

Set RAR="%strProgramFiles%\WinRAR\RAR.exe"
If Exist %RAR% ( Goto :RAR ) else ( Goto :Fail )
REM -----------------------------------------------------------------
:RAR
%RAR% a -m5 -y -df -hp%RAR_Password% "%CompressedFolder%" "%Folder2Compress%\">nul 2>&1
IF "%ERRORLEVEL%" EQU "0" ( GOTO Succes ) Else ( Goto Fail )
REM -----------------------------------------------------------------
:Succes
Echo(
Echo All Files are zipped succesfuly ! in "%CompressedFolder%" 
Echo All Files are zipped succesfuly ! in "%CompressedFolder%" > "%Log%"
Start "" /MAX "%Log%"
Timeout /T 3 /nobreak>nul
Exit /b
REM -----------------------------------------------------------------
:Fail
Color 0C
Echo(
echo There was an error ! 
echo There was an error ! >"%Log%"
Start /MAX "" "%Log%
Timeout /T 3 /nobreak>nul
REM -----------------------------------------------------------------