Skip to main content
Participant
April 30, 2022
Answered

Batch Rename Alphabetical listing of names

  • April 30, 2022
  • 3 replies
  • 428 views

I am working on a graduation magazine showing all of the graduating seniors for a school district. Sometimes I am provided the photos with the filename being the students last name then their first, and this is great as I have to alphabetize them. But sometimes the names are listed as First then last name and in previous years I would manually rename the files and it takes forever. 

 

I was hoping there was a way to do a batch rename where it would flip the words in the filename. For example I have the name John Doe. I want to renamed it to Doe John. Then to rename all files in the folder in this same format. 

 

I have searched and searched and I can not find a way it can be done. I am hoping someone has a solution as I don't want to spend the day renaming hundreds of files manually.

 

Thank you

This topic has been closed for replies.
Correct answer Stephen Marsh

@Jay2314322751rj – Assuming that you only have a first + last name separated by a single space, the following regular expression string substitution will do the job. Hyphenated names and three-word names may or may not be OK, you need to know and double-check your data:

 

Find:

 

(^.+)(?: )(.+)(\.[^\.]+$)

 

 

 

Replace:

 

$2 $1$3

 

 

 

 

Of course, the regular expression may need to be more advanced, taking in less simple/common names:

 

https://www.oreilly.com/library/view/regular-expressions-cookbook/9780596802837/ch04s18.html

 

^(.+?) ([^\s,]+)(,? (?:[JS]r\.?|III?|IV))?$
$2, $1$3

 

3 replies

Stephen Marsh
Community Expert
Community Expert
May 9, 2022

@Jay2314322751rj – so how did you go with my suggestion to use a regular expression based batch rename?

Participant
May 9, 2022

This helped thank you. I ended up going a bit further though and using scripts Excel and data merge to flow in my photos and names into my document. I did use those "codes" for a lack of a better word to flip the copy though. Thank you

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
May 3, 2022

@Jay2314322751rj – Assuming that you only have a first + last name separated by a single space, the following regular expression string substitution will do the job. Hyphenated names and three-word names may or may not be OK, you need to know and double-check your data:

 

Find:

 

(^.+)(?: )(.+)(\.[^\.]+$)

 

 

 

Replace:

 

$2 $1$3

 

 

 

 

Of course, the regular expression may need to be more advanced, taking in less simple/common names:

 

https://www.oreilly.com/library/view/regular-expressions-cookbook/9780596802837/ch04s18.html

 

^(.+?) ([^\s,]+)(,? (?:[JS]r\.?|III?|IV))?$
$2, $1$3

 

Legend
May 2, 2022

Use an app like Excel to fix the incoming data and then do your batch rename.

Participant
May 9, 2022

I managed to make it all work and using Excel was a big help. Thank you