rename baseball photo jpgs

A swapping-ground for Regular Expression syntax

rename baseball photo jpgs

Postby MJHJR » Sun Feb 27, 2011 4:09 am

I am having trouble trying to change baseball player photos from the names beginning with their first to their last with some of them having the team name and year after them.
For example: some have just : Adam_Kennedy.jpg Some have: Adam_Kennedy_LAA.jpg Some have: Adam_Kennedy_LAA_2010-2011.jpg
I want to cahnge them all to : Kennedy_Adam.jpg AND Kennedy_Adam_LAA.jpg AND Kennedy_Adam_LAA_2010-2011.jpg.In that order.
How do I go about doing this and can the whole folder with the different type jpg's be done all at the same time.

Thanks, Mike Hennelly
MJHJR
 
Posts: 12
Joined: Tue Jan 06, 2009 10:45 pm

Re: rename baseball photo jpgs

Postby Stefan » Sun Feb 27, 2011 9:22 pm

Hi Michael.


FROM:
Adam_Kennedy.jpg
Adam_Kennedy_LAA.jpg
Adam_Kennedy_LAA_2010-2011.jpg
TO:
Kennedy_Adam.jpg
Kennedy_Adam_LAA.jpg
Kennedy_Adam_LAA_2010-2011.jpg.

That's exchange the first two tokens/words.

Would be easy to get by
Repl.(3)
Repl.: Adam_Kennedy
With: Kennedy_Adam

But since you mentioned:
"How do I ... the whole folder with the different type jpg's be done all at the same time."
which i understand to match different names, we have to match the tokens by an regex, so

DO:
(until i or another one get an better idea)


0.)
Backup your files first before test this!


1.)
RegEx(1)
Match: (.*)_(.*)_(.*)_(.*)
Repla: \2_\1_\3_\4_

Rename
To get:
Adam_Kennedy.jpg
Adam_Kennedy_LAA.jpg
Kennedy_Adam_LAA_2010-2011_.jpg


2.)
RegEx(1)
Match: (.*)_(.*)_(.*[^_])$
Repla: \2_\1_\3_

Rename
To get:
Adam_Kennedy.jpg
Kennedy_Adam_LAA_.jpg
Kennedy_Adam_LAA_2010-2011_.jpg


3.)
RegEx(1)
Match: (.*)_(.*[^_])$
Repla: \2_\1

Rename
To get:
Kennedy_Adam.jpg
Kennedy_Adam_LAA_.jpg
Kennedy_Adam_LAA_2010-2011_.jpg



4.)
RegEx(1)
Match: (.*)_$
Repla: \1

Rename
To get:
Kennedy_Adam.jpg
Kennedy_Adam_LAA.jpg
Kennedy_Adam_LAA_2010-2011.jpg


:roll:

HTH? :wink:
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU

Re: rename baseball photo jpgs

Postby MJHJR » Wed Mar 02, 2011 5:35 am

Stefan,
Thanks a lot for your reply. I haven't got a chance to work on it yet. I'll let you know how it works out. There is 13,000 jpgs in the folder. I'm assuming looking at your reply that I'm suppose to follow in the order you have them written.
Thanks, again, Mike
MJHJR
 
Posts: 12
Joined: Tue Jan 06, 2009 10:45 pm

Re: rename baseball photo jpgs

Postby MJHJR » Sat Mar 05, 2011 4:41 am

Stefan,
I'm trying the first one( expression) and the names that are suppose to, change to green but when I hit the rename button I get a" can't rename message" because "Access is denied" on each of the names.
Mike Hennelly
MJHJR
 
Posts: 12
Joined: Tue Jan 06, 2009 10:45 pm

Re: rename baseball photo jpgs

Postby Stefan » Sat Mar 05, 2011 4:51 pm

MJHJR wrote:but when I hit the rename button I get a" can't rename message"
because "Access is denied" on each of the names.
I guess this is something with your system. Can't think that this on behalf of BRU.
You have not mentioned what OS you use and where the files are stored so no one can even try to help you.
Maybe you have Win7 and need to launch BRU with admin rights? ?? ?
What happens if you select one single file in BRU list and press F2-key, can you rename this file that way?

Maybe provide more infos and an link to an screenshot... perhaps someone can spot what is the culprit.
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU

Re: rename baseball photo jpgs

Postby MJHJR » Mon Mar 07, 2011 5:14 am

Stefan,
I have windows 7 and I opened the BRU in Admin rights and everything worked perfect, just has you instructed in your first post.
Thanks again. This really helps me a lot.
Mike Hennelly
MJHJR
 
Posts: 12
Joined: Tue Jan 06, 2009 10:45 pm

Re: rename baseball photo jpgs

Postby Stefan » Sun May 15, 2011 8:27 pm

While do some test (and i think i did remember something i read last week) i found an more elegant solution, doing all the above in one step:

FROM:
Adam_Kennedy.jpg
Adam_Kennedy_LAA.jpg
Adam_Kennedy_LAA_2010-2011.jpg
TO:
Kennedy_Adam.jpg
Kennedy_Adam_LAA.jpg
Kennedy_Adam_LAA_2010-2011.jpg.


RegEx(1)
Match: ([^_]+)_([^_]+)(.*)
Repla: \2_\1\3

Explanation:
([^_]+)_ ==> find one-or-more sign which are not an underscore, till an underscore is found ===> "Adam" + "_", store all match inside (..) in group 1
([^_]+) ====> again the same but till the end (or till an underscore is matched by next expression) ===> "Kennedy", store in group 2
(.*) =======> maybe match none-or-more of any sign ==> <none> or "_LAA" or "_LAA_2010-2011" , store in group 3
Replace with what is matched in group 2, add an underscore your own, then the content of group 1, then 3 if any ==> \2_\1\3
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU


Return to Regular Expressions