Finding longest filename

Hi!

Is there a way to find and select the longest filename on a press of a button? Or any method?

Thank you!

You could use a custom column like here

and here

and then simply sort and select.

Or write a script that loops through the files. Could be useful if you want to select more than one file in case there is a tie for first place.

Quickshot:

function OnClick(clickData) {
    var cmd = clickData.func.command;
    var tab = clickData.func.sourcetab;

    var maxLen = 0;
    for (var eSel = new Enumerator(tab.files); !eSel.atEnd(); eSel.moveNext()) {
        var fileNameLen = eSel.item().name.length;
        if (fileNameLen > maxLen) maxLen = fileNameLen;
    }

    cmd.ClearFiles();
    for (var eSel = new Enumerator(tab.files); !eSel.atEnd(); eSel.moveNext()) {
        var fileNameLen = eSel.item().name.length;
        if (fileNameLen == maxLen) cmd.AddFile(eSel.item());
    }
    cmd.RunCommand('Select NONE');
    cmd.RunCommand('Select FROMSCRIPT');
}

Select longest Filename.dcf (1.4 KB)

3 Likes

Thank you! Your code is just what i wanted! I didnt have time to try it until now. Works purrfectly. I appreciate your help. Scripting is still a thing i need to dig myself into.