batch file - How to extract all multi-volume RAR archives from subfolders of a folder? -
i search way unpack multi-volume archives after download via batch.
i download folders .r?? files in on ftp monitoring program , want winrar goes in first subfolder in source folder , start unpacking .r00, delete archive , move folder unpacked files new location.
then batch script should start process again next subfolder.
let's source folder c:\users\unpack
contains following subfolders 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
- subfolder1
i had start script in link below, script can't want, have started new question.
how unpack rar archives in subfolders of folder , delete archives?
the script in link above unrars files in subfolders , moves folder files new location. want script unrars , moves subfolder subfolder in source folder.
edit.1
if winrar ready first subfolder structure in source folder should this:
- source folder
- subfolder2
- archive2.r00
- archive2.r01
- yyy.txt
- subfolder3
- archive3.r00
- archive3.r01
- archive3.r02
- archive3.r04
- archive3.r05
- zzz.txt
- subfolder2
the files , folders in c:\users\new-location
should this:
- source folder
- subfolder1
- xxx.mp4
- xxx.txt
- subfolder2
- yyy.mp4
- yyy.txt
- subfolder3
- zzz.mp4
- zzz.txt
- subfolder1
a possible batch code task is:
@echo off setlocal enabledelayedexpansion set "basesourcefolder=c:\users\unpack" set "basetargetfolder=c:\users\new-location" /d %%d in ("%basesourcefolder%\*") ( 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 command prompt window displays command for parameter /d
means each directory matched *
in base source folder.
in loop first target folder name defined based on name of subfolder process. %%~fd
, %%~nxd
explained for /?
whereby folders not have extension , therefore %%~nd
enough.
next target folder created if not existing.
then rar.exe
executed extract multi-volume archive in current subfolder directly defined target folder.
*.r??
used make batch file work multi-volume archives old naming scheme archivename.r00
, archivename.r01
, ... better naming scheme archivename.part01.rar
, archivename.part02.rar
, ... used default winrar version 5.21. rar automatically skips archive files processed during extraction of multi-volume archive list matching *.r??
.
exit code of rar.exe
evaluated determine if error occurred. if exit code assigned errorlevel lower 1, there no error , 3 commands of if branch executed resulting in deleting first rar archive files.
the remaining files in current subfolder moved current target folder *.txt
file in folder structure example.
as current subfolder should empty now, command rd should able remove directory. in case of error because subfolder still not empty, subfolder remains in base source folder.
the base source folder empty if worked without error. commented line after for loop used remove empty base source folder well, keep folder if failed.
Comments
Post a Comment