使用循环在主文件夹中rar多个子文件夹 [英] Using a loop to rar multiple subfolders in a main folder

查看:121
本文介绍了使用循环在主文件夹中rar多个子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有3个子文件夹的主文件夹...

I have a main folder with 3 subfolders ...

  • C:\ Users \ Admin \ Folder
    • 文件夹1
    • 文件夹2
    • 文件夹3

    我希望批处理脚本获取第一个子目录Folder1,将其复制到另一个位置,例如C:\Temp\Folder,然后 WinRAR 开始存档Folder1.将Folder1复制到另一个位置后,可以在主文件夹中将其删除.

    I want that the batch script grabs the first subdirectory Folder1, copy it to another location, for example C:\Temp\Folder and than WinRAR starts to archive Folder1. After copying Folder1 to another location it can be deleted in the main folder.

    完成WinRAR 归档后,也可以在C:\Temp\Folder中删除Folder1.因此,只有.rar文件保留.

    After WinRAR finished archiving Folder1 can also be deleted in C:\Temp\Folder. So only the .rar files remain.

    然后该脚本从Folder2开始,并与Folder1相同.

    Then the script starts from new with Folder2 and do the same as with Folder1.

    到目前为止,我只有这个,还真的不知道如何实现以上内容.

    So far I have only this and do not really know how to implement the above.

    "C:\Program Files\WinRAR\Rar.exe" a -ep1 -mt5 -v50M -r -df "NAME-OF-THE-RAR-FILE" "C:\Users\Admin\Folder\*.*"
    

    推荐答案

    打开命令提示符窗口,键入并执行for /?并读取此命令的帮助输出. /D选项已经在第一个帮助页面上进行了说明,该页面用于在目录的每个子目录上执行命令.

    Open a command prompt window, type and execute for /? and read help output for this command. The option /D is explained already on first help page which is for executing commands on each subdirectory of a directory.

    下面的批处理文件使用控制台版本的 WinRAR 使用命令 m (移动=成功归档并删除)而不是命令C:\Users\Admin\Folder中的每个子文件夹归档> a ,并使用 -df 开关.

    The batch file below archives each subfolder in C:\Users\Admin\Folder using console version of WinRAR with command m (move = archive and delete on success) instead of command a with switch -df.

    @echo off
    for /D %%F in ("C:\Users\Admin\Folder\*") do (
        "%ProgramFiles%\WinRAR\Rar.exe" m -cfg- -ep1 -inul -m5 -mt5 -r -tl -v50M -y "%%~F.rar" "%%~F\"
        rd "%%~F"
    )
    

    所以结果是

    • C:\ Users \ Admin \ Folder
      Folder1.rar
      Folder2.rar
      Folder3.rar
    • C:\Users\Admin\Folder
      Folder1.rar
      Folder2.rar
      Folder3.rar

    根据文件夹中所有文件的大小以及每个文件夹需要存储50 MB的卷数,在归档和删除文件夹后,文件夹可以包含更多文件.

    The folder can contain even more files after archiving and deletion of the folders depending on size of all files of the folders and how much 50 MB volumes are necessary to archive each folder.

    由于在第三行末尾最后一个参数"%%~F\"中的反斜杠,因此文件Folder1.rar中不包含文件夹名称Folder1.

    The folder name Folder1 is not included in file Folder1.rar because of the backslash in last parameter "%%~F\" at end of third line.

    如果文件夹名称Folder1也应包含在存档文件Folder1.rar

    The batch file can be even easier if folder name Folder1 should be also included in the archive file Folder1.rar

    @echo off
    for /D %%F in ("C:\Users\Admin\Folder\*") do (
        "%ProgramFiles%\WinRAR\Rar.exe" m -cfg- -ep1 -inul -m5 -mt5 -r -tl -v50M -y "%%~F.rar" "%%~F"
    )
    

    我认为在这里不必将每个文件夹都复制到一个临时文件夹中以进行存档.

    I don't think that copying each folder to a temporary folder just for archiving is necessary here.

    这篇关于使用循环在主文件夹中rar多个子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆