Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Okay, so I have a few questions regarding some issues I am having right now:
1) I have a huge list of WinRAR files that were originally named in the format:
A.B.C.D.part001.rar
A.B.C.D.part002.rar
.
.
.I want to rename them to:
A.part001.rar
A.part002.rar
.
.
.2) Now my other problem is in the same stream of thought. I have a bunch of files in the format:
A.r01
A.r02
.
.
.Now I would like to rename them in the format:
A.001
A.002
.
.
.BUT, I would like to do in a manner that will make .r01 become .002, .r03 become .004. Is this possible?
Thanks For the Help,
JC

That's all possible with batch scripting. You just didn't mention if all the files from each issue are in a same directory, or if they're just listed on a file, whith various paths, spread over the computer. I'll assume they're all on the same directory (if that doesn't apply, don't use the following batch files!)
This should solve the first issue:
@echo off
for %%F in (*.rar) do (
for /F "tokens=1,5,6 delims=." %%S in ("%%F") do (
:: To activate script, remove the string
:: "echo.{demo}" from the next line
echo.{demo}rename "%%F" "%%S"
)
)That script is de-activated. If you run it like that, it will just display the actions it would take if active. If those are the desired actions, activate the script (read commented lines for doing so).
And this other batch file should solve the second issue:
@echo off
if "%1"=="GoTo" goto processfor %%F in (*.r*) do (
set file=%%F
set name=%%~nF
set ext=%%~xF
call %0 GoTo process
)
goto eof:process
set ext=%ext:~2%
for /F "delims=0123456789" %%C in ("%ext%") do goto eof
:loop1
if "%ext:~0,1%"=="0" (set ext=%ext:~1%&goto loop1)
set /A ext += 1
:loop2
if "%ext:~2,1%"=="" (set ext=0%ext%&goto loop2)
:: To activate script, remove the string
:: "echo.{demo}" from the next line
echo.{demo}rename "%file%" "%name%.%ext%":eof
That script is also de-activated.
-- Leonardo Pignataro - Secret_Doom --
secret_doom@hotmail.com
www.batch.hpg.com.br__________________________________________________________________

Wow, much more complex than I thought. Out of my league. I will try them out, the next time I need them and let you know. After looking at your site, I thought I'd mention that I am running XP, will these commands still work? All of the files in question are in the same directory.
Taking it a step further, how would I make the first set of WinRAR files output in the second manner,
A.B.C.D.Part001.rar --> A.Part001.rar (earlier post)
Can I make this become:
A.B.C.D.Part001.rar --> A.001 (where the extension of the output is the part number of the first one.)I really appreciate your help with this.
Thanks,
JC

After testing the first one:
I get the error:
"The system cannot find the drive specified."I counted it up and there isn't four parts to the file name, it's more like:
A.B.C.part001.rarI thought maybe that could be the error.

After running the second batch file I get the error:
{demo}rename "A.r06" "A.007"
{demo}rename "A.r07" "A.008"
{demo}rename "A.r08" "A.009"
The syntax of the command is incorrect.The directory had .r00 through .r55 and the whole output was that error.
Thanks,
JC

Jen Cheng wrote:
> After looking at your site, I thought I'd mention that
> I am running XP, will these commands still work?I've developed the batch scripts based on the OS you reported (Windows XP Pro). In fact, those batch files will only work on NT systems (Windows NT/2000/XP), they will not work on DOS/Win9x.
from response #2:
> Can I make this become:
> A.B.C.D.Part001.rar --> A.001 (where the extension of the
> output is the part number of the first one.)from response #3:
> I counted it up and there isn't four parts to the file name, it's more like:
> A.B.C.part001.rarAbout the first script, it was written wrong in the first place. Making the necessary corrections and adaptations according to your last inputs about that from responses #2 and #3, this is how it gets:
@echo off
for %%F in (*.rar) do (
for /F "tokens=1,4 delims=." %%A in ("%%F") do (
set file=%%F
set part0=%%A
set part1=
set part2=%%B
if not "%%B"=="" call %0 GoTo process
)
)
goto eof
:process
for /F "delims=0123456789 tokens=*" %%C in ("%part0:~0,1%!") do (
if "%%C"=="!" set part1=%part1%%part0:~0,1%
)
set part0=%part0:~1%
if defined part0 goto process:: To activate script, remove the string
:: "echo.{demo}" from the next line
echo.{demo}rename "%file%" "%part1%.%part2%":eof
However, the modifications I've made aren't related to that error you mentioned. I can't find any reason for that error to come up (so, it might come up again). You must cut-paste that code into a text file, save it with a .bat extention and run it from the folder where the files are. You've done that, right? You should not try to make any modifications on the script (appart from the ones described on the commented lines) and report errors generated by altered versions of my original code.
And for the second script, I see no reason at all why it shouldn't work. It has been tested throughly on Windows XP Professional and it's working just fine.
Make sure you're not screwing up the codes when cut-pasting them.
If you did nothing wrong on the cut-pasting process, if the problem is in the codes, I don't know how to solve either of the issues, since both codes work just fine here. Can anybody see any errors on those scripts?
-- Leonardo Pignataro - Secret_Doom --
secret_doom@hotmail.com
www.batch.hpg.com.br_________________________________________________________________

Hey, I posted the wrong script once more. I'm sorry about that. This is the script for the first task mentioned, which will get a file like the following;
something.anything.whatever.characters001.rar
and rename it to;
something.001
And it will apply that process to all files *.rar from the current directory, whenever possible. Designed and tested under Windows XP Professional, won't work out of NT systems.
@echo off
if "%1"=="GoTo" goto %2
for %%F in (*.rar) do (
for /F "tokens=1,4 delims=." %%A in ("%%F") do (
set file=%%F
set part0=%%B
set part1=%%A
set part2=
if not "%%B"=="" call %0 GoTo process
)
)
goto eof
:process
for /F "delims=0123456789 tokens=*" %%C in ("%part0:~0,1%!") do (
if "%%C"=="!" set part2=%part2%%part0:~0,1%
)
set part0=%part0:~1%
if defined part0 goto process:: To activate script, remove the string
:: "echo.{demo}" from the next line
echo.{demo}rename "%file%" "%part1%.%part2%":eof
The script for the second task remains (I don't see any errors).
-- Leonardo Pignataro - Secret_Doom --
secret_doom@hotmail.com
www.batch.hpg.com.br_________________________________________________________________

Wonderful the first method works:
A.B.C.D.Part001.rar --> A.001
I think I may have told you wrong in the first post, that's why it's not working for the second method. Here it is in more detail:
A.rar --> A.001
A.r00 --> A.002
A.r01 --> A.003
A.r02 --> A.004In the first post I did not include A.r00. Does that change the coding around?

Jen Cheng wrote:
> Wonderful the first method works:
> A.B.C.D.Part001.rar --> A.001You mean "A.B.C.Part001.rar", right? Good that it's working.
As for the second script, I might have found the reason for that error message you've mentioned. I would correct the bug, but now I've been confused by last message:
> I think I may have told you wrong in the
> first post, that's why it's not working
> for the second method. Here it is in more
> detail:
>
> A.rar --> A.001
> A.r00 --> A.002
> A.r01 --> A.003
> A.r02 --> A.004
>
> In the first post I did not include A.r00.
> Does that change the coding around?A.r00 becomes A.002? From what you first described, it would actually become A.001 (add 1 to the number, not two). You hadn't mentioned A.rar either. So, what is the process you want?
-- Leonardo Pignataro - Secret_Doom --
secret_doom@hotmail.com
www.batch.hpg.com.br

My first post was wrong, what I was trying to type was:
A.rar --> A.001
A.r00 --> A.002
A.r01 --> A.003
A.r02 --> A.004and yes I meant to say A.B.C instead of A.B.C.D
Thanks,
JC

Oh, it's clearer now. Try this batch file for that task:
@echo off
if "%1"=="GoTo" goto processfor %%F in (*.r*) do (
set file=%%F
set name=%%~nF
set ext=%%~xF
call %0 GoTo process
)
goto eof:process
if "%ext%"==".rar" (set ext=001&goto makeren)
set ext=%ext:~2%
if not defined ext goto eof
for /F "delims=0123456789" %%C in ("%ext%") do goto eof
:loop1
if "%ext:~0,1%"=="0" (set ext=%ext:~1%&goto loop1)
set /A ext += 2
:loop2
if "%ext:~2,1%"=="" (set ext=0%ext%&goto loop2)
:makeren
:: To activate script, remove the string
:: "echo.{demo}" from the next line
echo.{demo}rename "%file%" "%name%.%ext%":eof
That script is de-activated. If you run it like that, it will just display the actions it would take if active. If those are the desired actions, activate the script (read commented lines for doing so).
Tell me the results, ok?
-- Leonardo Pignataro - Secret_Doom --
secret_doom@hotmail.com
www.batch.hpg.com.br__________________________________________________________________

Hmmm... That's probably due to a difference between the Windows 2000 environment and the Windows XP's (which are very few), since the script still works on my system, Windows XP. Try this other version:
@echo off
if "%1"=="GoTo" goto processsetlocal
for %%F in (*.r*) do (
set file=%%F
set name=%%~nF
set ext=%%~xF
call %0 GoTo process
)
endlocal
goto eof:process
if "%ext%"==".rar" (set ext=001&goto makeren)
set ext=%ext:~2%
if not defined ext goto eof
set NaN=
for /F "tokens=* delims=0123456789" %%C in ("%ext%") do set NaN=%%C
if defined NaN goto eof
:loop1
if "%ext:~0,1%"=="0" (set ext=%ext:~1%&goto loop1)
set /A ext += 2
:loop2
if "%ext:~2,1%"=="" (set ext=0%ext%&goto loop2)
:makeren
:: To activate script, remove the string
:: "echo.{demo}" from the next line
echo.{demo}rename "%file%" "%name%.%ext%":eof
That script is de-activated. If you run it like that, it will just display the actions it would take if active. If those are the desired actions, activate the script (read commented lines for doing so).
Tell me the results, ok?
-- Leonardo Pignataro - Secret_Doom --
secret_doom@hotmail.com
www.batch.hpg.com.br_______________________________________________________________________

I don't know what's wrong, and it's taking me a while to find out. Try asking on the newsgroup alt.msdos.batch.nt.
It might be useful to include that script I wrote on the message.
-- Leonardo Pignataro - Secret_Doom --
secret_doom@hotmail.com
www.batch.hpg.com.br

![]() |
ideas for .bat files
|
Setup DOSes with no SETUP...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |