Computing.Net > Forums > Programming > Batch program

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch program

Reply to Message Icon

Name: aegis
Date: May 17, 2008 at 09:43:10 Pacific
OS: XP Home SP2
CPU/Ram: AMD 64 3.8/2gb
Product: Generic
Comment:

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.avi

Is this possible?



Sponsored Link
Ads by Google

Response Number 1
Name: devil_himself
Date: May 17, 2008 at 18:54:28 Pacific
Reply:

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"


0

Response Number 2
Name: aegis
Date: May 17, 2008 at 19:35:25 Pacific
Reply:

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)?


0

Response Number 3
Name: devil_himself
Date: May 17, 2008 at 19:51:34 Pacific
Reply:

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


0

Response Number 4
Name: aegis
Date: May 17, 2008 at 20:18:39 Pacific
Reply:

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"


0

Response Number 5
Name: devil_himself
Date: May 17, 2008 at 20:40:09 Pacific
Reply:

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"
)
)


0

Related Posts

See More



Response Number 6
Name: aegis
Date: May 17, 2008 at 20:53:44 Pacific
Reply:

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!


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch program

Advanced batch program www.computing.net/answers/programming/advanced-batch-program/14439.html

Batch Programming www.computing.net/answers/programming/batch-programming/3213.html

Batch Programming www.computing.net/answers/programming/batch-programming/15718.html