Button to rename files, sorting components of their names

I need a button to rename files like ...

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 "-"

Thanks a lot ...

Here's a Rename Preset which does that:

For reference:

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;
}
2 Likes

Wow, I am your Fan!!! Please send me your Autograph Card :stuck_out_tongue_winking_eye:

1 Like