1

Say I have a folder "C:\pokepoke" 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
Tom Zych
  • 13,329
  • 9
  • 36
  • 53
natli
  • 3,782
  • 11
  • 51
  • 82
  • These are nice questions, however they should be posted separately, in my opinion. – Andriy M Sep 03 '11 at 17:16
  • [This answer](http://stackoverflow.com/questions/138497/batch-scripting-iterating-over-files-in-a-directory/138581#138581) might help you with the second question, the one about `foreach` (subfolder). – Andriy M Sep 03 '11 at 17:22
  • @Andriy That's a very useful link for me Andriy, thanks. I "fixed" my main problem by altering the winrar batch script to automatically place the files in a subfolder after archiving, but I'm still hoping for an answer on how to do this with already existing archives. – natli Sep 05 '11 at 10:48

1 Answers1

2

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.

Andriy M
  • 76,112
  • 17
  • 94
  • 154