-1

I have some files (207 RAR files downloaded), and they don't have a proper name to refer each part/index, and if I want to extract them I should name them manually by checking volume index (from Properties section), and as you notice that can be too time-consuming

I thought that I might do it using a batch or a python script, so the first thing I needed to do is to get the volume index from CMD "7z i FileName.rar", but I couldn't find the volume index number (or maybe HEX) from the output Am I using the wrong command? Or maybe it is printed but I can't find it?

I attach one of RAR files output (Volume index is 18 [It is 19th part]) https://www.pastiebin.com/5cee55060c642

I would be thankful if you can help me.

0

1 Answer 1

0

You should be able to accomplish this with the l (list) command.

Here is a simple Windows command:

for %a in (*.rar) do @ECHO %a & "C:\Program Files\7-Zip\7z.exe" l %a | FIND "Index" & ECHO.

Here is the batch file version (%% instead of %):

@ECHO off
for %%a in (*.rar) do ECHO %%a & "C:\Program Files\7-Zip\7z.exe" l %%a | FIND "Index" & ECHO.

This will echo the filename and the "Volume Index" field from the output of the l (list) command for that file like the example below:

myFile.part1.rar
Volume Index = 0

myFile.part2.rar
Volume Index = 1

myFile.part3.rar
Volume Index = 2

To rename all of the files in order, you can use the following batch file.

Warning This will affect all files in the directory it's run in and the original file names will be lost.

@ECHO off

SET PATH=%PATH%;C:\Program Files\7-Zip\
for %%a in (*) do CALL:Index "%%~a"
GOTO:EOF

:Index
ECHO %~1
SETLOCAL EnableDelayedExpansion
for /f "tokens=3 delims== " %%a in ('7z.exe l "%~1" ^| FIND "Index"') do CALL:Rename "%~1" %%a
ENDLOCAL
GOTO:EOF

:Rename
SET /A Index=%2+1
REN "%~1" file%Index%.rar
2
  • Thanks! My problem is solved and even I don't need scripting as you did it. Now I got that I was using the wrong switch (i instead of l) and because "7z -h" echoed "Show information about supported formats" for "i" switch and I considered using it to get Volume Index but apparently, I should have used "l" switch. Thank you again May 29, 2019 at 19:49
  • (@ping me if you want me to delete this comment). I noticed this. It's not really relevant to your post as such, but I figured that it may give you a smile: gonzalu posted an Answer saying "Worthwelle DAMN IT, you ROCK! I have been hitting my head against a wall for over two hours trying to solve this. THANK YOU SO MUCH. I wish I had enough reputation to comment under your answer or to give you an UPVOTE!!"
    – Scratte
    Apr 19, 2021 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.