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?

3
  • do you mean: file.mp3.XXXX.mp3 -> afile.mp3.XXXX.mp3 -> bbfile.mp3.XXXX.mp3 -> b.bfile.mp3.XXXX.mp3? If "yes", you misspelled the "from" of the last step, that is not "afile" but "bbfile"...
    – kokbira
    Apr 28, 2011 at 12:07
  • why do you want to do it in 3 steps? why don't you want to do from "file.mp3.XXXX.mp3" to "b.bfile.mp3.XXXX.mp3"?
    – kokbira
    Apr 28, 2011 at 12:13
  • sorry i missed to note this answer @kokbira I just need to do it in 3 dos commands if thats possible
    – Siva
    Apr 28, 2011 at 18:34

3 Answers 3

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
3
  • answer fully tested :)
    – kokbira
    Apr 28, 2011 at 12:55
  • is it possible in 3 dos commands after each command i need to do things which the files before i can rename again..
    – Siva
    Apr 28, 2011 at 18:35
  • yes! but you have to know that when you call some commands, a) command console won't wait them to finish or b) they are only launching another command that will be executed separately. To avoid a), use "start /wait". To avoid b), try using a delay command (repeat "ping -n 11 localhost>nul" some times, or "timeout" or "choice" for Windows 7) after your entries... (source for delay commands: superuser.com/questions/66975/…)
    – kokbira
    Apr 28, 2011 at 20:58
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

4
  • a dos command would be very quicker I doubt we can do it in DOS/command prompt itself.. and I wont be able to install softwares in all the machines I will run this command
    – Siva
    Apr 28, 2011 at 11:08
  • Irfanview is a good solution for any files, one of the best for image files :). You have not to install to use it since you can download a ZIP package from Irfanview homepage or use a portable install or portable suite, like LiberKey with Irfanview app installed on it, on your pendrive - there is no need for admin privileges.
    – kokbira
    Apr 28, 2011 at 13:03
  • Thanks,I am not allowed to install any software in corporate network of my company... i know what u r thinking but we are struggling with this prob
    – Siva
    Apr 28, 2011 at 18:37
  • ach so. I'm thinking about to use that since you are allowed :)
    – kokbira
    Apr 28, 2011 at 20:59
0

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

2
  • individual commands for each step is fine.. also can you give link for The Rename ?
    – Siva
    Apr 28, 2011 at 10:56
  • herve-thouzard.com/the-rename - page is in French but utility runs in English.
    – LawrenceC
    Apr 28, 2011 at 14:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .