Rename One File To Another File Using FOR

November 6, 2010 at 22:51:18
Specs: Windows 7
I want to rename a .mp3 file to the same name as an .avi file heres an example

the .mp3 file will be "filename Tc0 L2 2ch 48 224 DELAY 0ms.mp3"
the .avi file will be "filename 101 what ever the title is.avi"

i want to rename the .mp3 to the filename of the .avi file, perferably using the FOR command so i can use variables, since each name is different.

ive looked around for a few hours but havent really came across what im looking for, probably doesnt help much that im not to experienced.

any help would be greatful


See More: Rename One File To Another File Using FOR

Report •


#1
November 7, 2010 at 01:41:28
Is there just one of each? If not, which file gets which name?


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
November 7, 2010 at 06:10:16
i have a bunch of mpgs in a folder named differently.

the .avi and .mp3 is made from encoding the .mpg so the file names match the .mpg other than the mp3 has this Tc0 L2 2ch 48 224 DELAY 0ms in the filename as well

i would like to rename the .mp3 to the same filename as the .avi for each .mpg (i guess is the best way to put it)

example: all files in the same folder

Some Show 01 Show Title.mpg
Some Show 01 Show Title.avi
Some Show 01 Show Title Tc0 L2 2ch 48 224 DELAY 0ms.mp3

Some Show 02 Show Title.mpg
Some Show 02 Show Title.avi
Some Show 02 Show Title Tc0 L2 2ch 48 224 DELAY 0ms.mp3

after renaming would like it to be

Some Show 01 Show Title.mpg
Some Show 01 Show Title.avi
Some Show 01 Show Title.mp3

Some Show 02 Show Title.mpg
Some Show 02 Show Title.avi
Some Show 02 Show Title.mp3


Report •

#3
November 7, 2010 at 09:53:02
@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%f in ('dir /b *.mp3') do (
set name=%%~nf
set name=!name: Tc0 L2 2ch 48 224 DELAY 0ms=!
ren %%f !name!.*
)

Report •

Related Solutions

#4
November 7, 2010 at 10:10:12
when tryin to run what you posted in a bat file i get this

the syntax of the command is incorrect.

Tc0 L2 2ch 48 224 DELAY 0ms <-- this in the filename of the .mp3 will not always be the same thing it will change depending on each file.


Report •

#5
November 7, 2010 at 11:18:39
Sorry about that, the command

ren %%f !name!.*


should have been

ren "%%f" "!name!.*"

because the filename contains spaces and so the ren command thought we were giving it more than two arguments.

But now you've told me the trailing bits of the file name could vary, the solution is more complicated. I'll have to think about it a little (and get some sleep first) and probably someone else will find a solution before I do.


Report •

#6
November 7, 2010 at 11:46:54
no problem thanks for the help

sorry about not mentioning the file name to the .mp3 would vary


Report •

#7
November 7, 2010 at 19:48:43
I hope this helps.

@echo off
setlocal enabledelayedexpansion
for %%a in (*.avi) do (
set /a n+=1
set aviname!n!=%%~na
)
for /l %%b in (1,1,%n%) do (
rename "!aviname%%b!*.mp3" "!aviname%%b!.mp3"
)
:
cls
pause


Report •

#8
November 7, 2010 at 21:04:33
sweet works like a charm. thanks very much :)

if you have the time, could you explain how the script works, i understand some of it but not all of it. would like to learn a bit also lol.


Report •

#9
November 8, 2010 at 08:30:56
:: Not obvious what incrementing has to do with this.
:: But I'll stay tuned.

@echo off & setLocal EnableDELAYedeXpansion

for /f "tokens=* delims= " %%a in ('dir/b *.avi') do (
ren "%%~Na*.mp3" "%%~Na.mp3"
)


=====================================
Life is too important to be taken seriously.

M2


Report •


Ask Question