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
Save ColumnRankByCreated.js.txt toββββ
%appdata%\GPSoftware\Directory Opus\Script AddIns
Try out the column with
Set COLUMNSTOGGLE="scp:RankByCreated/RankByCreated(!,a,0)"
Set COLUMNSTOGGLE="created(!,a,0)"
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)
}