Tony, Carl, Andy - 2002.txt
--> Andy, Carl, Tony - 2002.txt
or
New York, Dublin, Atlanta, Berlin, London - George.txt
--> Atlanta, Berlin, Dublin, London, New York - George.txt
Alphabetical sort of the filename part before the "-"
function OnGetNewName(getNewNameData)
{
// Separate name and extension.
var stem = getNewNameData.item.name_stem;
var ext = getNewNameData.item.ext;
// Separate anything after the last " - ".
var suffix = "";
var suffixPos = stem.lastIndexOf(" - ");
if (suffixPos != -1)
{
suffix = stem.substr(suffixPos);
stem = stem.substr(0, suffixPos);
}
// Sort components between ", "
stem = stem.split(", ").sort().join(", ");
// Put everything back together
return stem + suffix + ext;
}