Overview
This script provides columns which show the name and date of the newest file below each folder.
The script adds ten columns. You'll only use one or two at a time.
Five of the columns report on files directly below each folder, ignoring sub-folders:
- Newest File: Date, time and name.
- Newest File Date: Date only.
- Newest File Date-Time: Date and time.
- Newest File Time: Time only.
- Newest File Name: Name only.
The other five columns report on files anywhere below each folder, including sub-folders:
- Newest File (Recursive): Date, time and name.
- Newest File Date (Recursive): Date only.
- Newest File Date-Time (Recursive): Date and time.
- Newest File Time (Recursive): Time only.
- Newest File Name (Recursive): Name only.
The combined date and name columns let you turn on just one column to see both things, but the information is harder to read because the dates, times and filenames do not line up nicely. This isn't the case with the separate date and name columns, but then you have two columns instead of one. It's up to you which you use.
Sorting and grouping:
- The combined columns sort by date/time and do not currently support grouping.
- The date columns sort by date/time, and groups like the internal date columns do.
- The name columns sort by name (alphabetically), and do not currently support grouping.
These columns read the list of files below each folder every time the file display is refreshed. For the recursive ones, that includes listing all sub-folders, and if you turn them on at the root of a drive the script will have to list every file on the drive. With large, complex directory trees, it can take a few seconds (and lots of disk/network activity) for the information to appear. You probably don't want to turn these columns on all the time, or in folders like C:\. Use them when you need them and turn them off afterwards.
Installation (Opus 13 and above):
- Download and double-click Newest File Column.opusscriptinstall (1.6 KB) v1.4
Installation (Opus 12 and bellow):
- Download Newest File Column.js.txt (5.5 KB) v1.4
- Open Preferences / Toolbars / Scripts to display the list of scripts.
- Drag the downloaded Newest File Column.js.txt to the list.
History
- v1.4 (30/Sep/2024)
- Fixed error with empty folders when IncludeFolders was on.
- v1.3 (29/Sep/2024)
- Added config option to show data for individual files (on by default).
- Added config option to consider (sub)-folder dates when calculating the newest date (off by default).
- v1.2 (Not published until 1.3)
- Added time-only versions of the columns.
- v1.1 (15/Apr/2017)
- "Subscript out of range" errors should be fixed now. They were due to this.
- v1.0 (2014)
- Initial version.
Usage
If the script is installed, you will see its columns under the Scripts category in the Folder Options dialog, or the menu you get from right-clicking your existing columns.
Add the columns manually as you would any others.
Alternatively, you might want to use a command, like this, which toggles a pair of the columns at once:
@ifset:COLUMNSTOGGLE="scp:Newest File Column/NewestFileDate"
Set COLUMNSREMOVE="scp:Newest File Column/NewestFileDate"
Set COLUMNSREMOVE="scp:Newest File Column/NewestFileName"
@ifset:else
Set COLUMNSADD="scp:Newest File Column/NewestFileDate"
Set COLUMNSADD="scp:Newest File Column/NewestFileName"
The command editor's menus will work out the column names for you, so don't worry about doing that by hand.
Configuration
-
Go to the list of scripts.
Opus 13 & above: Settings > Scripts.
Opus 12 & below: Preferences / Toolbars / Scripts.
You can also runPrefs SCRIPTS
to open the appropriate UI in either version. -
Configure the Newest File Column script:
Configuration options are:
-
IncludeFolders: False by default. When false, and calculating the column for a folder, the dates of the folder itself and all sub-folders are ignored; only file dates are considered. When true, if the folder itself or one of the sub-folders has the newest date, it will be what the column shows.
-
SingleFiles: True by default. When false, the column will be blank for individual files. When true, the column will show the date, name, etc. of the file (treating individual files as if they were folders that only contain themselves).
The Script Itself
Expand the section below if you want to look at the script to see how it works.
The script
If you just want to use the script, the downloads above are easier.
The script code is reproduced here to help people looking for scripting techniques on the forum.
This script is in JScript.
// Newest File Column
// (C) 2014-2024 Leo Davidson
//
// This is a script for Directory Opus.
// See http://www.gpsoft.com.au/DScripts/redirect.asp?page=scripts for development information.
function OnInit(initData)
{
initData.name = "Newest File Column";
initData.desc = "Columns to show the newest file below each folder";
initData.copyright = "(C) 2014-2024 Leo Davidson";
initData.url = "https://resource.dopus.com/t/custom-column-newest-file/18765";
initData.version = "1.4";
initData.default_enable = true;
initData.min_version = "11.5.2"
initData.config.IncludeFolders = false;
initData.config.SingleFiles = true;
initData.config_desc = DOpus.Create.Map(
"IncludeFolders", "Whether (sub-)folder dates are considered, or only files, when finding the newest item.",
"SingleFiles", "If true, the column shows the modified date of individual files. If false, it column is blank for files.");
var col = initData.AddColumn();
col.name = "NewestFile";
col.method = "OnNewestFile";
col.label = "Newest File";
// col.header = "Newest File";
col.justify = "left";
col.autogroup = true;
col.multicol = true;
var col = initData.AddColumn();
col.name = "NewestFileRec";
col.method = "OnNewestFileRec";
col.label = "Newest File (Recursive)";
col.header = "Newest File (Rec)";
col.justify = "left";
col.autogroup = true;
col.multicol = true;
var col = initData.AddColumn();
col.name = "NewestFileDate";
col.method = "OnNewestFile";
col.label = "Newest File Date-Time";
col.header = "Newest Date-Time";
col.justify = "right";
col.autogroup = true;
col.type = "datetime";
col.multicol = true;
var col = initData.AddColumn();
col.name = "NewestFileDateRec";
col.method = "OnNewestFileRec";
col.label = "Newest File Date-Time (Recursive)";
col.header = "Newest Date-Time (Rec)"
col.justify = "right";
col.autogroup = true;
col.type = "datetime";
col.multicol = true;
var col = initData.AddColumn();
col.name = "NewestFileDateOnly";
col.method = "OnNewestFile";
col.label = "Newest File Date";
col.header = "Newest Date";
col.justify = "right";
col.autogroup = true;
col.type = "date";
col.multicol = true;
var col = initData.AddColumn();
col.name = "NewestFileDateOnlyRec";
col.method = "OnNewestFileRec";
col.label = "Newest File Date (Recursive)";
col.header = "Newest Date (Rec)"
col.justify = "right";
col.autogroup = true;
col.type = "date";
col.multicol = true;
var col = initData.AddColumn();
col.name = "NewestFileTime";
col.method = "OnNewestFile";
col.label = "Newest File Time";
col.header = "Newest Time";
col.justify = "right";
col.autogroup = true;
col.type = "time";
col.multicol = true;
var col = initData.AddColumn();
col.name = "NewestFileTimeRec";
col.method = "OnNewestFileRec";
col.label = "Newest File Time (Recursive)";
col.header = "Newest Time (Rec)"
col.justify = "right";
col.autogroup = true;
col.type = "time";
col.multicol = true;
var col = initData.AddColumn();
col.name = "NewestFileName";
col.method = "OnNewestFile";
col.label = "Newest File Name";
col.header = "Newest Name"
col.justify = "left";
col.autogroup = true;
col.multicol = true;
var col = initData.AddColumn();
col.name = "NewestFileNameRec";
col.method = "OnNewestFileRec";
col.label = "Newest File Name (Recursive)";
col.header = "Newest Name (Rec)"
col.justify = "left";
col.autogroup = true;
col.multicol = true;
}
function OnNewestFile(scriptColData)
{
NewestFileMain(scriptColData, false);
}
function OnNewestFileRec(scriptColData)
{
NewestFileMain(scriptColData, true);
}
function BestItemName(item)
{
if (item.display_name != "")
return item.display_name;
return item.name;
}
function NewestFileMain(scriptColData, IsRecursive)
{
var SingleFiles = Script.config.SingleFiles;
var IncludeFolders = Script.config.IncludeFolders;
var NewestItem = null;
if (scriptColData.item.is_dir)
{
if (IncludeFolders)
{
NewestItem = scriptColData.item;
}
var FolderEnum = DOpus.FSUtil.ReadDir(scriptColData.item, IsRecursive);
while (!FolderEnum.complete)
{
FolderItem = FolderEnum.next;
if (IncludeFolders || !FolderItem.is_dir)
{
if (NewestItem == null || NewestItem.modify.Compare(FolderItem.modify) < 0)
{
NewestItem = FolderItem;
}
}
}
}
else if (SingleFiles)
{
NewestItem = scriptColData.item;
}
if (NewestItem != null)
{
var isRec = (IsRecursive ? "Rec" : "");
if (scriptColData.columns.exists("NewestFileName" + isRec))
{
scriptColData.columns("NewestFileName" + isRec).value = BestItemName(NewestItem) + "";
}
if (scriptColData.columns.exists("NewestFileDate" + isRec))
{
scriptColData.columns("NewestFileDate" + isRec).value = NewestItem.modify;
}
if (scriptColData.columns.exists("NewestFileDateOnly" + isRec))
{
scriptColData.columns("NewestFileDateOnly" + isRec).value = NewestItem.modify;
}
if (scriptColData.columns.exists("NewestFileTime" + isRec))
{
scriptColData.columns("NewestFileTime" + isRec).value = NewestItem.modify;
}
if (scriptColData.columns.exists("NewestFile" + isRec))
{
DateVar = new Date(NewestItem.modify);
scriptColData.columns("NewestFile" + isRec).value = NewestItem.modify.Format() + " " + BestItemName(NewestItem);
scriptColData.columns("NewestFile" + isRec).sort = DateVar.toJSON() + " " + BestItemName(NewestItem);
}
}
}
Alternative:
A similar but slightly different script can be found here: