?
Solved

Need to edit thousands of file names.

Posted on 2011-05-09
6
Medium Priority
?
398 Views
Last Modified: 2012-05-11
Hello,

I have a job where the provider mis-named appx 50,000 .jpg images.

They are currently named as such: IMG_2011_05_SYSTEM_FIVE_00001.jpg, IMG_2011_15_SYSTEM_FIVE_00002.jpg, etc...

and I need them all named without the "_SYSTEM_FIVE" like: IMG_2011_00001.jpg, IMG_2011_00002.jpg, etc... They would continue on as 00003, 00004, 00005, all the way up to ~50000.

I know how to use ren to change a name or add characters, but I can't figure out how to remove characters from the name,

Anyone know how?

Thanks!
0
Comment
Question by:funkyjoe1
  • 4
  • 2
6 Comments
 
LVL 59

Expert Comment

by:Bill Prew
ID: 35724225
Are they all in the same folder?

~bp
0
 
LVL 59

Accepted Solution

by:
Bill Prew earned 2000 total points
ID: 35724275
Not sure if I understood the requirement or not.  You said:

==> I need them all named without the "_SYSTEM_FIVE"

but in your example

IMG_2011_05_SYSTEM_FIVE_00001.jpg

became

IMG_2011_00001.jpg

Here's a simple BAT script to just remove the original string you mentioned.  Save as a BAT file and adjust the SET of the folder where the files live.  Not that right now it will just ECHO the REN command it would execute to the screen.  If these look like what you need then remove the ECHO on the REN command and run for real.

@echo off
setlocal EnableDelayedExpansion
set BaseDir=c:\temp
for %%A in ("%BaseDir%\*.jpg") do (
  set OldName=%%~nA
  set NewName=!OldName:_SYSTEM_FIVE=!
  ECHO ren "%%~A" "!NewName!.jpg"
)

Open in new window

~bp
0
 

Author Comment

by:funkyjoe1
ID: 35724612
Hi Bill,

Thanks for the help.

Yes "_SYSTEM_FIVE" is what I need removed from the file names. I ran your BAT and with

@echo off outputs this to screen:
"IMG_2011_05_SYSTEM_FIVE_00001.jpg" "IMG_2011_05_00001.jpg"

When I remove @echo off I get this to screen:
set OldName=IMG_2011_05_SYSTEM_FIVE_00001
 set NewName=!OldName:_SYSTEM_FIVE=!
 ECHO ren "c:\test\2011_05_SYSTEM_FIVE_00001.jpg" "!NewName!.jpg"
)
ren "c:\test\2011_05_SYSTEM_FIVE_00001.jpg" "2011_05_00001.jpg"

But, the actual files in c:\test are not changed?

Did I miss something?

Thanks!


0
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
LVL 59

Expert Comment

by:Bill Prew
ID: 35725321
Yes, you don't want to change the first @ECHO OFF line, but rather the line"

  ECHO ren "%%~A" "!NewName!.jpg"

~bp
0
 

Author Comment

by:funkyjoe1
ID: 35729621
Worked perfectly! Thanks!
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 35731945
Great, welcome.

~bp
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question