Sorting a portion of the filename

Download the script:

Name Substrings.js.txt (830 Bytes)

Then open Preferences / Toolbars / Scripts and drag it to the list of scripts there.

You can then find a Scripts > Name Substring column.

The column will show the filenames, with the first 11 characters removed. (You can edit the script to change the number of characters for other uses.)

Sort by the column as you would a normal one.


Script code (same as in the .js.txt file above):

// Called by Directory Opus to initialize the script
function OnInit(initData)
{
	initData.name = "Name Substrings";
	initData.version = "1.0";
	initData.copyright = "(c) 2017 Leo Davidson";
	initData.url = "https://resource.dopus.com/t/sorting-a-portion-of-the-filename/25966";
	initData.desc = "Adds a column with substrings of each file's name, for custom sorting.";
	initData.default_enable = true;
	initData.min_version = "12.0";

	var col = initData.AddColumn();
	col.name = "NameSubstring";
	col.method = "OnNameSubstring";
	col.label = "Substring";
	col.type = "String";
	col.justify = "left";
	col.autogroup = true;
	col.namerefresh = true;
}


// Implement the OnNameSubstring column
function OnNameSubstring(scriptColData)
{
	scriptColData.value = scriptColData.item.name.substring(11);
}