ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE. Software > Post New Requests Here

comma remover and name order changer


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. 

RegexRenamer that I mention here should do the job easily.

A picture and all that ...

comma remover and  name order changer

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

--- Code: Text [email protected] offrem NameMunge.cmdremrem Call as: NameMunge.cmd <path>remrem eg. NameMunge.cmd . pushd %1for /f "tokens=1,2,3,4 usebackq delims=,." %%a in (`dir /b *.jpg`) do (call :Getnames %%a %%b %%c %%d) goto :Exit :Getnamesset sname=%1for /f "tokens=* delims= " %%a in ("%2") do set fname=%%aset ext=%4set oldname=%sname%, %fname% %3.%ext%set newname=%fname% %3. %sname%.%ext%echo.Old name="%oldname%"echo.New name="%newname%"ren "%oldname%" "%newname%"goto :EOF    :Exit

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.

Instead of "Abbott, John B.jpg  I would have "John B. Abbott.jpg"
-questorfla (October 16, 2013, 05:39 PM)
--- End quote ---

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.

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 ---#SingleInstance, force FileSelectFolder, WhichFolder  ; Ask the user to pick a folder.Loop, %WhichFolder%\*.*, , 1{        file_name := A_LoopFileName         StringReplace, file_name, file_name, `, , ,All    ;//removes the commas        StringReplace, file_name, file_name, ., %A_Space%, All     ;//changes the period to space                name_array := StrSplit(file_name, A_Space)   ;//break it apart using the spaces & put into array                final_name := name_array[2] " " name_array[3] " " name_array[1] "." name_array[4]    ;//combine array to new file struct                FileMove, %WhichFolder%\%A_LoopfileName%, %WhichFolder%\%final_name%  ;//renames a single file} msgbox, File Name(s) have been changed! exitapp Esc::   ;//panic button        criticalexitapp


[0] Message Index

Go to full version