如何解开所有的RAR压缩文件夹中的所有子文件夹,然后删除档案? [英] How to unpack all rar archives in all subfolders of a folder and then delete the archives?

查看:198
本文介绍了如何解开所有的RAR压缩文件夹中的所有子文件夹,然后删除档案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要解压缩一些子文件夹这是在主文件夹中的所有文件,拆封后删除xxx.rar文件,并用这些文件到另一个位置移动的文件夹。

I want to unpack all files in some subfolders which are in a main folder, delete the xxx.rar files after unpacking and move the folder with the files to another location.


  • 主要文件夹

    • 子Folder1中的(带.rar文件)

    • 子FOLDER2的(带.rar文件)

    • 子Folder3的(带.rar文件)

    • Main Folder
      • Sub Folder1 (with .rar files)
      • Sub Folder2 (with .rar files)
      • Sub Folder3 (with .rar files)

      这是我的批处理脚本,至今工作。

      This my batch script and works so far.

      SET "sourcefolder=C:\Users\Unpack"
      FOR /R %sourcefolder% %%X in (*.rar) do (
          pushd "%%~dpX"
          "C:\Program Files\WinRAR\Rar.exe" x -y "%%X" "*.*" && del "*.rar"
          popd
      )
      for /d /r %sourcefolder% %%x in (*) do move "%%x" "C:\Users\New-Location")
      

      不过,我想,每一个子文件夹的文件解压后立即采取行动,新地点文件夹中,不单只是一切都已经在主文件夹解压。

      But I want that every subfolder whose files are unpacked immediately moved to the "New-Location" folder and not only after everything has been unpacked in the main folder.

      有些想法我已经在code改变?

      Some ideas what I have to change in the code?

      推荐答案

      这个小批量code希望你想要做什么。

      This little batch code hopefully does what you want.

      @echo off
      set "SourceFolder=C:\Users\Unpack"
      set "TargetFolder=C:\Users\New-Location"
      if not exist "%TargetFolder%" md "%TargetFolder%"
      "%ProgramFiles%\WinRAR\Rar.exe" x -ad -cfg- -idq -r -y "%SourceFolder%\*.rar" "%TargetFolder%"
      del /F /Q /S "%SourceFolder%\*.rar">nul
      for /D %%D in ("%SourceFolder%\*") do rd "%%D" 2>nul
      

      控制台版本 RAR.EXE 比大多数用户不会阅读更强大的手动 Rar.txt 存储在程序的文件的文件夹的 WinRAR的的都知道的。

      Console version Rar.exe is more powerful than most users never reading the manual Rar.txt stored in program files folder of WinRAR are aware of.

      在开箱源文件夹中的所有子文件夹的所有* .rar文件,可直接与 RAR.EXE ,因为它可以看出,因为没有完成了循环批处理code使用。 RAR.EXE 支持在DECOM pressing RAR存档文件通配符和开关 -r 的命令中使用 X 的结果也处理所有的RAR压缩文件中的所有子文件夹的手册说明。

      Unpacking all *.rar files in all subfolders of a source folder can be done directly with Rar.exe as it can be seen because no for loop is used in batch code. Rar.exe supports wildcards on decompressing RAR archive files and switch -r used on command x results in processing all RAR archive files also in all subfolders as the manual explains.

      选项 -ad 意思的添加压缩文件名到目标路径的可从的 RAR 的命令行中删除,如果所有档案包含一个独特的文件夹名称,或所有档案应解压到同一目录与前一解压previous存档覆盖已存在的文件。 -ad 的使用取决于归档文件的内容。

      Option -ad meaning append archive name to destination path could be removed from RAR command line if all archives contain a unique folder name, or all archives should be unpacked into same directory with overwriting already existing files from a previous archive unpacked before. Usage of -ad depends on contents of the archive files.

      选项 -idq 意味着安静模式,即只输出错误信息,但是这是更快没有进展信息。

      Option -idq means quiet mode, i.e. output only error messages, but no progress information which is faster.

      所有的* .rar文件拆包后,他们的删除也做没有环路命令的删除也支持所有的删除* .rar文件中的所有子文件夹一个文件夹中。

      The deletion of all *.rar files after unpacking them is done also without a for loop as command del supports also deletion of all *.rar files in all subfolders of a folder.

      编辑:

      有关在源文件夹中所有子文件夹中删除是删除所有的RAR文件,但保留源文件夹,一个作为后空循环终于必要的,因为加入到上述code

      For deletion of all subfolders in source folder being empty after deleting all RAR files, but keeping the source folder, a for loop is finally necessary as added to code above.

      子文件夹不为空由命令第三届忽略,因为这些参数 / S / Q 不使用这将删除子文件夹,即使不已经完全是空的。

      Subfolders not being empty are ignored by command rd because the parameters /S /Q are not used which would delete a subfolder even if not already completely empty.

      RD 输出为标准错误如果一个子文件夹删除不为空,将被重定向到设备的 NUL的错误信息可想喝preSS吧。

      The error message of rd output to stderr if a subfolder to remove is not empty is redirected to device nul to suppress it.

      要删除源文件夹的所有子文件夹独立于什么解压所有的RAR压缩文件后,这些子文件夹包含,但保留源文件夹,批量code以上需要的最后两行由以下行来代替:

      To delete all subfolders of source folder independent on what those subfolders contain after unpacking all RAR archives, but keep the source folder, the last two lines of batch code above need to be replaced by the following line:

      for /D %%D in ("%SourceFolder%\*") do rd /S /Q "%%D" 2>nul
      

      和用于与它的所有子文件夹删除源文件夹,批次code以上需要的最后两行可以由下面的行替换:

      And for deleting the source folder with all its subfolders, the last two lines of batch code above need to be replaced by the following line:

      rd /S /Q "%SourceFolder%" 2>nul
      

      请注意:一个文件夹,可以通过删除 RD 只有当它是不是在Windows上的任​​何正在运行的进程的当前工作目录

      Note: A folder can be removed by rd only if it is not the current working directory for any running process on Windows.

      帮助在批处理文件中使用的每个命令可以打开命令提示符窗口进行读取和运行有:

      Help for each command used in the batch file can be read by opening a command prompt window and run there:


      • DEL /?

      • 为/?

      • 如果/?

      • MD /?

      • RD /?

      • 设置/?

      • 为%ProgramFiles%\\ WinRAR的\\ RAR.EXE/?

      • del /?
      • for /?
      • if /?
      • md /?
      • rd /?
      • set /?
      • "%ProgramFiles%\WinRAR\Rar.exe" /?

      这篇关于如何解开所有的RAR压缩文件夹中的所有子文件夹,然后删除档案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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