【问题标题】:RAR files with password and enryption using batch使用批处理的带有密码和加密的 RAR 文件
【发布时间】:2020-10-24 05:26:06
【问题描述】:

我在驱动器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"

【问题讨论】:

    标签: batch-file batch-processing


    【解决方案1】:

    试试这个示例代码:

    @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 -----------------------------------------------------------------
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-10
      相关资源
      最近更新 更多