Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
You guys have saved me a 'tremendous' amount of work already, but I'm going to push my luck and ask for some more help.
I have a bunch of sub folders with media files. The files have names that begin with a 4 digit number followed by a space and then the actual name. For example:
0035 Gourmet Night at the Villa.avi
0036 The Hotel Inspector.avi
0037 Waldorf Salad.avi
I would like to search the sub folders for any files where the actual name begins with 'the ' and remove all those 'the 's. So in the preceeding example I would end up with:0035 Gourmet Night at the Villa.avi
0036 Hotel Inspector.avi
0037 Waldorf Salad.aviIs this possible?

try this
@echo off
for /f "tokens=1,2*" %%a in ('dir /b /a-d *.avi') do if '%%b' == 'The' echo ren "%%a %%b %%c" "%%a %%c"

Thanks devil_himself, I really appreciate the help!
I must be doing something wrong, because I immediately get a 'File not found'.
I have the main folder 'Tester' with three subfolders 'test1', 'test2' and 'test3'. The sub folders each have a few files.
I put the bat file in the 'tester' folder, turned 'echo on' and ran it and got the 'file not found'.I would like to change the '*.avi' to '*.*', because there are various type of media files in the folders. Is that ok? If not I can create a batch file for each type.
And can I change the 'the' to 'the ' (add a space)?

here ya go
@echo off
for /f "tokens=1,2*" %%a in ('dir /b /s /a-d') do if '%%b' == 'The' echo ren "%%a %%b %%c" "%%a %%c"added -
/S Displays files in specified directory and all subdirectories.and all file types

Hey, that 'seemed' to work. It looks to me like it echoed out the correct commands, but when I removed the 'echo' in the bat file I get a bunch of 'The syntax for the command is not correct' errors.
Here's an example of what is shown when I run it with the 'echo':ren "H:\testbed\tester\test1\0102 The Builders.avi" "H:\testbed\tester\test1\0102 Builders.avi"

ahh. i haven't written batch from a long time now
i have tested this script with the examples you gave above .remove echo to make it rename the files
@echo off
for /f "tokens=*" %%a in ('dir /b /s /a-d') do (
for /f "tokens=1,2*" %%b in ("%%~nxa") do if '%%c'=='The' echo ren "%%a" "%%b %%d"
)
)

That worked perfectly devil_himself! It doesn't seem like you lost anything!
This saves me an enormous amount of work. You have helped out a senile old man and I appreciate it more than I can say.
I'm gonna do it for real now.
Thanks very, very much!

![]() |
![]() |
![]() |

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