RankByCreated (Rank files within their parent folder based on creation date)

This add-in introduces a column named RankByCreated, which ranks files within their parent folder based on creation date. The newest file is assigned rank 1, the second-newest rank 2, and so on.

The script evaluates only the files' parent folders, meaning it works independently of their position in collections or nested folder views (e.g., Expanded Folders or Flat View).

This column is particularly useful in filters, for example: "Copy the three newest files."

The script can easily be adapted to reverse the ranking order or to use the modification date or other ranking criteria. Leave a comment if you need any assistance.

How to set up and use

:one: Save ColumnRankByCreated.js.txt to   ↓

%appdata%\GPSoftware\Directory Opus\Script AddIns

:two: Try out the column with

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

:three: Use it in a filter

// Copy the three newest files
Copy FILTERDEF script match RankByCreated/RankByCreated < 4

Things you might enjoy reading

How to use buttons and scripts from this forum

The script's inner workings

JScript
function OnInit(initData) {
    initData.name = 'RankByCreated';
    initData.version = '2026-04-24';
    initData.url = 'https://resource.dopus.com/t/rankbycreated-rank-files-within-their-parent-folder-based-on-creation-date/59245';
    initData.desc = 'Rank files within their parent folder based on creation date';
    initData.default_enable = true;
    initData.min_version = '12.0';
}

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

var fsu = DOpus.FSUtil();
var folderRankCache = null;

function OnColumn(scriptColData) {
    scriptColData.value = 0;    // folders, or items without a parent

    var item = scriptColData.item;

    if (item.is_dir) return;

    var parentFolder = item.path;
    if (!parentFolder) return;

    if (!folderRankCache) {
        folderRankCache = DOpus.Create().Map();
    }

    var rankLookup = null;

    if (folderRankCache.exists(parentFolder)) {
        rankLookup = folderRankCache.get(parentFolder);
    } else {
        var fileDataList = [];

        var folderEnum = fsu.ReadDir(parentFolder);
        while (!folderEnum.complete) {
            var folderItem = folderEnum.Next();
            if (folderItem.is_dir) continue;
            fileDataList.push([folderItem.realpath, folderItem.create.GetTime()]);  // instead of .create, you could use .modify or .access for different ranking criteria
        }
        folderEnum.Close();

        fileDataList.sort(function (a, b) {
            // return a[1] - b[1];     // oldest first
            return b[1] - a[1];     // newest first
        });

        rankLookup = DOpus.Create().Map();

        for (var i = 0; i < fileDataList.length; i++) {
            rankLookup.set(fileDataList[i][0], i + 1);
        }

        folderRankCache.set(parentFolder, rankLookup);
    }

    scriptColData.value = rankLookup.get(item.realpath) || -1;  // -1 for items not found in the ranking (shouldn't happen unless they were created after the cache was built)
}
7 Likes

Wow! This is fantastic! This makes things so easy when backups are constantly happening. Thank You

I find this incredibly useful because it makes copying and moving files much easier. But what really surprised me is how valuable it becomes as a column. Being able to sort by it gives me an instant view of what I’m currently working on β€” for example, the most recently created files. Having that at a glance is extremely helpful.