如何从文件夹的子文件夹中提取所有多卷 RAR 档案? [英] How to extract all multi-volume RAR archives from subfolders of a folder?

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

问题描述

我正在寻找一种在批量下载后解压缩多卷档案的方法.

我使用 .r?? 下载文件夹文件通过 FTP 监控程序并希望 WinRAR 进入源文件夹中的第一个子文件夹并开始解压 .r00,删除存档并将带有解压文件的文件夹移动到新位置.

然后批处理脚本应使用下一个子文件夹再次启动此过程.

假设源文件夹 C:\Users\unpack 包含以下包含文件的子文件夹:

  • 源文件夹
    • 子文件夹 1
      • Archive1.r00
      • Archive1.r01
      • Archive1.r02
      • xxx.txt
    • 子文件夹 2
      • Archive2.r00
      • Archive2.r01
      • yyy.txt
    • 子文件夹3
      • Archive3.r00
      • Archive3.r01
      • Archive3.r02
      • Archive3.r04
      • Archive3.r05
      • zzz.txt

我已经开始使用下面链接中的脚本执行此操作,但是该脚本无法执行我想要的操作,因此我提出了一个新问题.

解决方案

此任务可能的批处理代码是:

@echo offsetlocal EnableDelayedExpansion设置BaseSourceFolder=C:\Users\Unpack"设置BaseTargetFolder=C:\Users\New-Location"对于/D %%D in ("%BaseSourceFolder%\*") 做 (设置TargetFolder=%BaseTargetFolder%\%%~nxD"如果不存在!TargetFolder!"md "!目标文件夹!""%ProgramFiles%\WinRAR\Rar.exe" x -cfg- -idq -y "%%~fD\*.r??"!目标文件夹!"如果不是错误级别 1 (del/F/Q "%%~fD\*.r??"move/Y "%%~fD\*" "!TargetFolder!">nul 2>nulrd "%%~fD" 2>nul))rem rd "%BaseSourceFolder%" 2>nul本地端

在命令提示符窗口中执行的

for/? 显示命令 for 的帮助,参数 /D 这意味着对于每个由 <匹配的目录code>* 在基本源文件夹中.

在循环中,首先根据要处理的子文件夹的名称定义目标文件夹名称.%%~fD%%~nxD 也由 for/? 解释,其中文件夹通常没有扩展名,因此 %%~nD 通常也足够了.

接下来创建这个目标文件夹,如果不存在的话.

然后执行Rar.exe,将当前子文件夹中的多卷压缩文件直接解压到定义的目标文件夹中.

*.r?? 用于使该批处理文件适用于具有旧命名方案的多卷存档 ArchiveName.r00, ArchiveName.r01, ... 以及更好的命名方案 ArchiveName.part01.rar, ArchiveName.part02.rar, ... WinRAR 5.21 版.RAR 会自动跳过在从匹配 *.r?? 的列表中提取多卷存档期间已经处理过的存档文件.

评估 Rar.exe 的退出代码以确定是否发生任何错误.如果分配给 errorlevel 的退出代码低于 1,则没有错误并且 if 分支的 3 个命令被执行,导致首先删除所有 RAR 存档文件.>

当前子文件夹中的剩余文件也移动到当前目标文件夹中,即文件夹结构示例中的*.txt文件.

由于当前子文件夹现在应该是空的,命令 rd 应该能够删除该目录.如果由于子文件夹仍不为空而出现错误,则子文件夹仍保留在基本源文件夹中.

如果一切正常且没有错误,则基本源文件夹为空.for 循环后的注释行也可用于删除空的基本源文件夹,但如果出现任何故障,请保留该文件夹.

I search for a way to unpack multi-volume archives after download via batch.

I download folders with .r?? files in it over a FTP monitoring program and want that WinRAR goes in the first subfolder in the source folder and start unpacking .r00, delete the archive and move the folder with the unpacked files to a new location.

Then the batch script should start this process again with the next subfolder.

Let's say the source folder C:\Users\unpack contains following subfolders with files:

  • source folder
    • subfolder1
      • Archive1.r00
      • Archive1.r01
      • Archive1.r02
      • xxx.txt
    • subfolder2
      • Archive2.r00
      • Archive2.r01
      • yyy.txt
    • subfolder3
      • Archive3.r00
      • Archive3.r01
      • Archive3.r02
      • Archive3.r04
      • Archive3.r05
      • zzz.txt

I had start to do this with the script in the link below, but that script can't do what I want, so I have started a new question.

How to unpack all rar archives in all subfolders of a folder and then delete the archives?

The script in the link above unrars all files in all subfolders and then moves the folder with its files to a new location. I want that the script unrars and moves subfolder for subfolder in the source folder.

Edit.1

If winrar is ready with the first subfolder the structure in the source folder should look like this:

  • source folder
    • subfolder2
      • Archive2.r00
      • Archive2.r01
      • yyy.txt
    • subfolder3
      • Archive3.r00
      • Archive3.r01
      • Archive3.r02
      • Archive3.r04
      • Archive3.r05
      • zzz.txt

The files and folders in C:\Users\new-location should look like this:

  • source folder
    • subfolder1
      • xxx.mp4
      • xxx.txt
    • subfolder2
      • yyy.mp4
      • yyy.txt
    • subfolder3
      • zzz.mp4
      • zzz.txt

解决方案

A possible batch code for this task is:

@echo off
setlocal EnableDelayedExpansion
set "BaseSourceFolder=C:\Users\Unpack"
set "BaseTargetFolder=C:\Users\New-Location"
for /D %%D in ("%BaseSourceFolder%\*") do (
    set "TargetFolder=%BaseTargetFolder%\%%~nxD"
    if not exist "!TargetFolder!" md "!TargetFolder!"
    "%ProgramFiles%\WinRAR\Rar.exe" x -cfg- -idq -y "%%~fD\*.r??" "!TargetFolder!"
    if not errorlevel 1 (
        del /F /Q "%%~fD\*.r??"
        move /Y "%%~fD\*" "!TargetFolder!">nul 2>nul
        rd "%%~fD" 2>nul
    )
)
rem rd "%BaseSourceFolder%" 2>nul
endlocal

for /? executed in a command prompt window displays help for command for with parameter /D which means for each directory matched by * in base source folder.

In the loop first the target folder name is defined based on name of the subfolder to process. %%~fD and %%~nxD are also explained by for /? whereby folders usually do not have an extension and therefore %%~nD is often also enough.

Next this target folder is created if not already existing.

Then Rar.exe is executed to extract the multi-volume archive in the current subfolder directly to the defined target folder.

*.r?? is used to make this batch file work for multi-volume archives with old naming scheme ArchiveName.r00, ArchiveName.r01, ... as well as better naming scheme ArchiveName.part01.rar, ArchiveName.part02.rar, ... which is used by default by WinRAR version 5.21. RAR automatically skips the archive files processed already during extraction of a multi-volume archive from the list matching *.r??.

Exit code of Rar.exe is evaluated to determine if any error occurred. If exit code assigned to errorlevel is lower than 1, there was no error and the 3 commands of the if branch are executed resulting in deleting first all RAR archive files.

The remaining files in current subfolder are also moved to the current target folder which is the *.txt file in the folder structure example.

As the current subfolder should be empty now, the command rd should be able to remove the directory. In case of an error because subfolder is still not empty, the subfolder remains in base source folder.

The base source folder is empty if everything worked without an error. The commented line after for loop could be used to remove the empty base source folder as well, but keep the folder if anything failed.

这篇关于如何从文件夹的子文件夹中提取所有多卷 RAR 档案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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