Grouping of File and Folder Names

Here's a script column that assigns files to groups of numbers.

function OnInit(initData) {
    initData.name = 'LogGroup';
    initData.version = '2023-07-06';
    initData.url = 'https://resource.dopus.com/t/grouping-of-file-and-folder-names/44942';
    initData.desc = '';
    initData.default_enable = true;
    initData.min_version = '12.0';
}

function OnAddColumns(addColData) {
    var col = addColData.AddColumn();
    col.name = 'LogGroup';
    col.justify = 'right';
    col.method = 'OnColumn';
}

function OnColumn(scriptColData) {
    var item = scriptColData.item;
    if (item.is_dir) return;

    var itemNo = item.name_stem.replace(/0*(\d+).*/, '$1');

    if (itemNo == '') {
        scriptColData.value = 'none';
        return;
    }

    var groupSize = Math.pow(10, itemNo.length - 1);
    if (groupSize < 10) groupSize = 10;

    var start = Math.floor(Number(itemNo) / groupSize) * groupSize;
    var end = start + groupSize - 1;
    scriptColData.value = start + '..' + end;
}

To install, save ColumnLogGroup.js.txt to

%appdata%\GPSoftware\Directory Opus\Script AddIns

The column can be toggled with

Set COLUMNSTOGGLE="scp:LogGroup/LogGroup(!,a,0)"

The files can be grouped with

Set GROUPBY=scp:LogGroup/LogGroup

If all of this sounds a bit strange, read here

How to use buttons and scripts from this forum

1 Like