Rename a folder based on the file type extension

This requires Opus 12.0.8 or above as it uses the new $.\ feature which makes it easier to move things into sub-folders of the starting point.

Before:


After:

What the rename dialog looks like:


The script code:

function OnGetNewName(getNewNameData)
{
	// Only rename files.
	if (getNewNameData.item.is_dir)
		return;

	// Get the extension, lower case, without the dot.
	extLower = String(getNewNameData.newname_ext).toLowerCase();
	if (extLower.length == 0 || extLower.charAt(0) != '.')
		return;
	extLower = extLower.substr(1);

	// Work out which folder to put the file in.
	folder = "";
	switch(extLower)
	{
	case "doc":
	case "docx":
	case "docm":
	case "dot":
	case "dotx":
	case "dotm":
	case "dochtml":
	case "dothtml":
		folder = "MS Office\\word\\" + extLower;
		break;
	default:
		folder = "Unknown Files\\Unknown (" + extLower + ")";
		break;
	}

	// $.\ means the "base" folder that the rename starts in.
	// This requires Opus 12.0.8 or later.
	return "$.\\" + folder + "\\" + getNewNameData.newname;
}