.Bat script to rename files in child folder.

January 4, 2011 at 06:57:57
Specs: Windows 7
I wanted to develop a .bat script that changes the type of a file if it exist. The problem is the movies are 2 levels deep and I need help entering the next folder. My structure is set up ass follows. Movies\Forest Gump\ForestGump.mk4 where I would like to run the script at the Movies Level and rename "ForestGump.mk4" to "ForestGump.mp4" only if the file is a type of .mk4. Any insight???

See More: .Bat script to rename files in child folder.

Report •


#1
January 4, 2011 at 07:18:33
@echo off
setLocal EnableDELAYedeXpansion

for /f "tokens=*" %%a in ('dir C:\movies\*. /ad /b /s') do (
  cd\"%%a"
  ren *.mk4 *.mp4
)

Note: this is not tested. I will test it and get back to you. I just wrote it off the top of my head.


Report •

#2
January 4, 2011 at 07:51:58
Note the changes...

@echo off
setLocal EnableDELAYedeXpansion

for /f "tokens=*" %%a in ('dir C:\movies\ /ad /b /s') do (
  ren "%%a\*.mk4" "*.mp4"
)

Also this is assuming the path to MOVIES is c:\movies. You may need to change it to include the full path. It may be c:\users\yournamehere\movies\ If you are using Windows Vista or newer.


Report •

#3
January 4, 2011 at 07:59:56
Thanks for the quick reply. However it is not working. Trying to debug but havent been successful thus far.

Report •

Related Solutions

#4
January 4, 2011 at 13:23:22
Hmmm, it worked for me. Again you must specify the exact directory the files are located in. What is it?

"Movies\Forest Gump\"

will not do. Is it in the C: drive if so what is the root directory.


Report •

#5
January 4, 2011 at 14:16:43
The exact directory is "C:\Videos\Movies\" I just replace
('dir C:\movies\ /ad /b /s')
with
('dir C:\Videos\Movies\ /ad /b /s').........right????


Also were do I place the .bat file. I place it in the Movies directory right.


Report •

#6
January 4, 2011 at 14:30:57

('dir C:\Videos\Movies\ /ad /b /s') -> Correct.

It does not matter where you run the batch file from.

You will get errors on directories that have no MK4 files but the ones that do will rename the files. I ran the following code on my computer's music because I don't have the movies you have; and it worked...

@echo off
setLocal EnableDELAYedeXpansion

for /f "tokens=*" %%a in ('dir C:\users\jflagg\music\ /ad /b /s') do (
    ren "%%a\*.mp3" "*.mp4"
    echo ren "%%a\*.mp3" "*.mp4
    pause
)

Why it is not working for you, I have no idea.


Report •

#7
January 4, 2011 at 15:29:41
I ran your script also ace_omega and it works great, nice job. Maybe if the OP gave a little bit more information about the errors he is getting, or a little bit more information about directories we can get it worked out.

Can I put a question here?


Report •

Ask Question