• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Simple batch file commands?

edro

Lifer
Lets say I have about 2000 files that I want to modify the file names of.

image001(E).jpg
image002(E).jpg
image003(E).jpg
etc...

I want to remove the "(E)" from all of them.

Is there a .BAT file command to do that (using a .BAT file I mean)?

THANKS!
 
The good old FOR command should come in handy for this. Use ( and ) as your delims, isolate the first and third tokens.
 
@echo off
cd C:\test
for %(E) in (*.zip) ren %

any help? I have no idea what I am doing...
 
Originally posted by: djheater
A for route is more complicated than I believe you need.

Try

REN *(E).jpg *.jpg

Tell me if it works.

i am guessing that wont work in windows

linux - yes
 
Originally posted by: edro13
@echo off
cd C:\test
for %(E) in (*.zip) ren %

any help? I have no idea what I am doing...

The tough part is that you need to get the original filename, too.
The for command will look something like:
FOR /F "tokens=1,3 delims=()" %%i IN ('<path>') DO REN %%i(E)%%j %%i%%j

%%i should resolve to image001 and %%j should resolve to .jpg

That might not be 100% correct, but it's close...

do a FOR /? for more information.
 
Ha... Every program in the world has already been written by someone

Just use This I downloaded it and it worked for your purpose.

🙂

The trouble with the for is that iterating tokens is not done for filenames, just content??
 
Originally posted by: djheater
The trouble with the for is that iterating tokens is not done for filenames, just content??

For is the Leatherman Tool of DOS commands.

Give it a path and it will work the filenames in that path.
Give it a file and it will work the lines in the file.
It does some other funky stuff, too.
 
Originally posted by: Jzero
Originally posted by: djheater
The trouble with the for is that iterating tokens is not done for filenames, just content??

For is the Leatherman Tool of DOS commands.

Give it a path and it will work the filenames in that path.
Give it a file and it will work the lines in the file.
It does some other funky stuff, too.

Hmmmm... something like

FOR /f "tokens=1,2 delims=()" %%s in ('DIR /b C:\TEMP*.jpg') do ("REN %%S(E)%%T %%S%%T")

????
 
Originally posted by: djheater
Originally posted by: Jzero
Originally posted by: djheater
The trouble with the for is that iterating tokens is not done for filenames, just content??

For is the Leatherman Tool of DOS commands.

Give it a path and it will work the filenames in that path.
Give it a file and it will work the lines in the file.
It does some other funky stuff, too.

Hmmmm... something like

FOR /f "tokens=1,2 delims=()" %%s in ('DIR /b C:\TEMP*.jpg') do ("REN %%S(E)%%T %%S%%T")

????

That may work with some tweaking. You could also do it like:
FOR /F ... IN ('C:\TEMP') ...
Provided that you want to change every file in C:\TEMP
 
Originally posted by: Jzero
Originally posted by: djheater
Originally posted by: Jzero
Originally posted by: djheater
The trouble with the for is that iterating tokens is not done for filenames, just content??

For is the Leatherman Tool of DOS commands.

Give it a path and it will work the filenames in that path.
Give it a file and it will work the lines in the file.
It does some other funky stuff, too.

Hmmmm... something like

FOR /f "tokens=1,2 delims=()" %%s in ('DIR /b C:\TEMP*.jpg') do ("REN %%S(E)%%T %%S%%T")

????

That may work with some tweaking. You could also do it like:
FOR /F ... IN ('C:\TEMP') ...
Provided that you want to change every file in C:\TEMP

Yeh,

The closest I could get was:
C:\Documents and Settings\dheater>FOR /f "tokens=1,3 delims=()" %s in ('DIR /b C
:\TEMP\testcmd\*.jpg') do ('REN %s(E)%t %s%t')


But the problem is the end pren in the REN statement. It keeps causing the do to bork out because it perceives it as the end of the statement....
bleh... there's probably a clever way to nest it....
 
Originally posted by: djheater
Originally posted by: Jzero
Originally posted by: djheater
Originally posted by: Jzero
Originally posted by: djheater
The trouble with the for is that iterating tokens is not done for filenames, just content??

For is the Leatherman Tool of DOS commands.

Give it a path and it will work the filenames in that path.
Give it a file and it will work the lines in the file.
It does some other funky stuff, too.

Hmmmm... something like

FOR /f "tokens=1,2 delims=()" %%s in ('DIR /b C:\TEMP*.jpg') do ("REN %%S(E)%%T %%S%%T")

????

That may work with some tweaking. You could also do it like:
FOR /F ... IN ('C:\TEMP') ...
Provided that you want to change every file in C:\TEMP

Yeh,

The closest I could get was:
C:\Documents and Settings\dheater>FOR /f "tokens=1,3 delims=()" %s in ('DIR /b C
:\TEMP\testcmd\*.jpg') do ('REN %s(E)%t %s%t')


But the problem is the end pren in the REN statement. It keeps causing the do to bork out because it perceives it as the end of the statement....
bleh... there's probably a clever way to nest it....

You should be able to ditch the parens around the DO. I don't even know if you need quotes, although putting them around the file names might be a good idea in case there are spaces.
 
Originally posted by: tkdkid
This worked for me in win2k:

ren image???(e).jpg image???.jpg

HA!

I knew there had to be a simpler way.... I forgot all about the ? character... You sir are teh winnar
 
Originally posted by: djheater
Originally posted by: tkdkid
This worked for me in win2k:

ren image???(e).jpg image???.jpg

HA!

I knew there had to be a simpler way.... I forgot all about the ? character... You sir are teh winnar

I didn't even know you could do that. That's great. I'll have to remember that.
 
Back
Top