Grouping multiple split-up RAR archives by folder with Windows batch file
Say I have a folder "C:\pokepok开发者_StackOverflowe" with archives like:
trequetry.part01.rar
trequetry.part02.rar
trequetry.part03.rar
and
replokitro.part01.rar
replokitro.part02.rar
replokitro.part03.rar
replokitro.part04.rar
and so on. How can I make it so the first set of archives ends up in C:\pokepoke\trequetry
and the second in C:\pokepoke\replokitro
and so on. So basically filter on X.partX.rar or something in that direction.
I am trying to batch-create recovery files with par2
for lots of split-up archives so in addition to my main question, I would also like to find out how to perform a for-each on all subfolders in C:\pokepoke
so I can run the following code on it once all archives are moved to their respective folders:
FOR /R %%g IN (.) DO C:\WINDOWS\par2.exe c -r10 -s384000 "%%g\%%~ng.par2" "%%g\*"
del /q *.par2
To help you with your first question, the following script worked for me:
@ECHO OFF
SET "origloc=D:\path\to\archives"
FOR %%F IN ("%origloc%\*.part*.rar") DO CALL :process "%%F"
GOTO :EOF
:process
CALL :checkpath "%~dpn1"
MOVE %1 "%subfolder%" >NUL
GOTO :EOF
:checkpath
SET "subfolder=%~dpn1"
IF NOT EXIST "%subfolder%\" MKDIR "%subfolder%"
GOTO :EOF
This script searches for *.part*.rar
files in the specified folder. It applies the ~dpn
modifier to every name twice to strip the name of the 'double extension' .partNN.rar
, then uses the resulting name as the subfolder name.
Optionally you could change the first SET command like this:
SET "origloc=%~1"
to be able to call the script for an arbitrary path, passing the path as a parameter.
精彩评论