avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Tuesday June 18, 2024, 1:31 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: comma remover and name order changer  (Read 5191 times)


  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 570
  • Fighting Slime all the Time
    • View Profile
    • Donate to Member
comma remover and name order changer
« on: October 16, 2013, 05:39 PM »
I don't know a better way to explain it but I have a folder of about 200 jpg files.
I need to change the file names from "last name," "first name" "middle initial.".  The program that creates the photo display uses the actual name of the jpeg as the title of the photo which makes sense.  But the person who created the list was obviously someone is used to working in a large office and filing by last name.
I found some utilities that can reverse alphabetize etc and I feel sure that if I asked Google the right question someone has already written such a script.
So that the comma would trigger deleting everything in front of it and the space after it and adding what it deleted to the end of the name.
Instead of "Abbott, John B.jpg  I would have "John B. Abbott.jpg"

This is probably a perfect task for Excel using the comma delimiter but I never use Excel for anything much,  Just thought I would ask if anyone has ever seen such a tool before I write my own. I hate to try to reinvent the wheel. 


  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,643
    • View Profile
    • Donate to Member
Re: comma remover and name order changer
« Reply #1 on: October 16, 2013, 08:03 PM »
RegexRenamer that I mention here should do the job easily.

A picture and all that ...

2013-10-17 12_25_18-Program Manager.pngcomma remover and  name order changer

Or for the low-tech non-recursive, non-error checking version:

Code: Text [Select]
  1. @echo off
  2. rem NameMunge.cmd
  3. rem
  4. rem Call as: NameMunge.cmd <path>
  5. rem
  6. rem eg. NameMunge.cmd .
  8. pushd %1
  9. for /f "tokens=1,2,3,4 usebackq delims=,." %%a in (`dir /b *.jpg`) do (call :Getnames %%a %%b %%c %%d)
  11. goto :Exit
  13. :Getnames
  14. set sname=%1
  15. for /f "tokens=* delims= " %%a in ("%2") do set fname=%%a
  16. set ext=%4
  17. set oldname=%sname%, %fname% %3.%ext%
  18. set newname=%fname% %3. %sname%.%ext%
  19. echo.Old name="%oldname%"
  20. echo.New name="%newname%"
  21. ren "%oldname%" "%newname%"
  22. goto :EOF
  24. :Exit
« Last Edit: October 16, 2013, 09:56 PM by 4wd »


  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 13,288
  • Tell me something you don't know...
    • View Profile
    • Renegade Minds
    • Donate to Member
Re: comma remover and name order changer
« Reply #2 on: October 16, 2013, 10:18 PM »
This is what I use for those kinds of things:

So for what you're looking for:

([^,]+), (.+)\.jpg

$2 $1.jpg

Or maybe:
\2 \1

I forget which syntax it uses for replacements at the moment.
Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker


  • Supporting Member
  • Joined in 2011
  • **
  • Posts: 4,642
    • View Profile
    • Donate to Member
Re: comma remover and name order changer
« Reply #3 on: October 16, 2013, 11:33 PM »
Instead of "Abbott, John B.jpg  I would have "John B. Abbott.jpg"

I'll just add some random advice that "John B. Abbott.jpg" is maybe not the best file name, just for cosmetic reasons.

1. A few edge cases get grumpy at dots anywhere else in the filename except the extension
2. Even though you don't use Excel, a trick I found is that "John-B Abbott"  and "Billy Crystal-4th" are exactly two terms, so that programs (including Excel) can count the number of terms in a string, and then so things so for example the next term after that is maybe date taken, and you don't have an "Abott" date just because not all names have middle initials etc.


  • Member
  • Joined in 2013
  • **
  • Posts: 36
    • View Profile
    • Donate to Member
Re: comma remover and name order changer
« Reply #4 on: October 24, 2013, 12:09 PM »
Assuming all your file_names have "Lastname, Firstname Middle_init.ext" this should work for your purposes.  However, it WILL NOT work if they do not have a middle initial.  I based this upon your example above... "Abbott, John B.jpg"

Here's an easy example of what you need.  I know that this can be done via RegEx & other various ways, but I wanted to keep it simple. 
I felt it was easier to understand if you modified the code yourself. 

Feel free use as needed.


Code: Autohotkey [Select]
  2. FileSelectFolder, WhichFolder  ; Ask the user to pick a folder.
  3. Loop, %WhichFolder%\*.*, , 1
  4. {
  5.         file_name := A_LoopFileName
  7.         StringReplace, file_name, file_name, `, , ,All    ;//removes the commas
  8.         StringReplace, file_name, file_name, ., %A_Space%, All     ;//changes the period to space
  10.         name_array := StrSplit(file_name, A_Space)   ;//break it apart using the spaces & put into array
  12.         final_name := name_array[2] " " name_array[3] " " name_array[1] "." name_array[4]    ;//combine array to new file struct
  14.         FileMove, %WhichFolder%\%A_LoopfileName%, %WhichFolder%\%final_name%  ;//renames a single file
  15. }
  17. msgbox, File Name(s) have been changed!
  20. Esc::   ;//panic button
  21.         critical