2

Windows XP command prompt rename command for this task?

Rename...

file.mp3.0001.mp3  
file.mp3.0002.mp3  
file.mp3.0003.mp3  
file.mp3.0004.mp3  

to

afile.mp3.0001.mp3  
afile.mp3.0002.mp3  
afile.mp3.0003.mp3  
afile.mp3.0004.mp3  

and then

afile.mp3.0001.mp3  
afile.mp3.0002.mp3  
afile.mp3.0003.mp3  
afile.mp3.0004.mp3  

to

bbfile.mp3.0001.mp3  
bbfile.mp3.0002.mp3  
bbfile.mp3.0003.mp3  
bbfile.mp3.0004.mp3  

and then

afile.mp3.0001.mp3  
afile.mp3.0002.mp3  
afile.mp3.0003.mp3  
afile.mp3.0004.mp3  

to

b.bfile.mp3.0001.mp3  
b.bfile.mp3.0002.mp3  
b.bfile.mp3.0003.mp3  
b.bfile.mp3.0004.mp3  

How can I do this?

Andrea
  • 1,536
Siva
  • 175

3 Answers3

5

just a console command to rename from "*.mp3" to "bb*.mp3" - it functions:

for /f "delims=" %i in ('dir /b /on /a-d *.mp3') do ren "%i%" "b.b%i"

but if you want it in steps, it will be more difficult, like my solution in How to rename 80.000 files at once in Windows - I edited it to your requirements :), fully tested way, and it searches in subfolders too:

  • create a batch file with the following commands
  • change variable parameters to what you want
    • path: put inside "" the root path of your files (e.g. "C:\documents and settings\user\desktop\new folder"
    • numfirstchars2replaceX: put a number with the first characters to replace for eaxh X step (in your case, numfirstchars2replace1=0, numfirstchars2replace2=1, numfirstchars2replace1=1)
    • str2putX: put a string to be added as a prefix of the new filename for each X step (in your case, str2put1=a, str2put2=bb, str2put3=b.)
  • run it in a folder different from where the files are


@echo off

::only to tell user what this bat are doing
echo.1.initializing...

::enable that thing to allow, for example, incremental counter in a for loop :)
echo.- EnableDelayedExpansion
SETLOCAL EnableDelayedExpansion

::variables
echo.- variables
:: - place here the absolute root path of your files
set path="put here absolute path where are the root folder of your files"
set pathbak=%cd%
set numfirstchars2replace1=0
set numfirstchars2replace2=1
set numfirstchars2replace3=1
set str2put1=a
set str2put2=bb
set str2put3=b.

::go to %path% and its driveletter
echo.- entering the path you want
for /f "delims=" %%i in ('echo.%path%') do %%~di
cd %path%

::search all subfolders and save them to a temp file
echo.- searching for subfolders
echo.%path%>%temp%\tmpvar.txt
for /f "delims=" %%i in ('dir /s /b /on /ad') do echo."%%i">>%temp%\tmpvar.txt

::execute command for root folder and all found subfolders
echo.
echo.2.executing...

echo.- step 1
for /f "delims=" %%i in (%temp%\tmpvar.txt) do (
  cd %%i
  echo.- in folder: %%i
  for /f "delims=" %%j in ('dir /b /on /a-d *.mp3') do (
    set newname=%%j
    set newname=!newname:~%numfirstchars2replace1%,1000!
    echo.- renaming from "%%j" to "%str2put1%!newname!"...
    ren "%%j" "%str2put1%!newname!"
  )
)

echo.- step 2
for /f "delims=" %%i in (%temp%\tmpvar.txt) do (
  cd %%i
  echo.- in folder: %%i
  for /f "delims=" %%j in ('dir /b /on /a-d *.mp3') do (
    set newname=%%j
    set newname=!newname:~%numfirstchars2replace2%,1000!
    echo.- renaming from "%%j" to "%str2put2%!newname!"...
    ren "%%j" "%str2put2%!newname!"
  )
)

echo.- step 3
for /f "delims=" %%i in (%temp%\tmpvar.txt) do (
  cd %%i
  echo.- in folder: %%i
  for /f "delims=" %%j in ('dir /b /on /a-d *.mp3') do (
    set newname=%%j
    set newname=!newname:~%numfirstchars2replace3%,1000!
    echo.- renaming from "%%j" to "%str2put3%!newname!"...
    ren "%%j" "%str2put3%!newname!"
  )
)

echo.
echo.3.exiting...
::return to %pathbak% and its driveletter
for /f "delims=" %%i in ('echo.%pathbak%') do %%~di
cd %pathbak%

@echo on
kokbira
  • 5,429
0

You probably need a more advanced renaming utility such as THE Rename.

Gareth
  • 19,080
LawrenceC
  • 75,182
0

I don't know any ways of doing this through PowerShell or IrfanView, although made for images will also do batch renaming. It might be possible to script this, however I am not 100% sure.

Screenshot

Gareth
  • 19,080
tombull89
  • 6,699