Edit: Consolidated postings and comments as of 2023-05-02.
This add-in generates a custom column EverythingFolderSize which leverages voidtools' Everything to display folder sizes. The advantage of an Everything column is its faster performance compared to Opus' built-in column.
Upon execution, the script stores the data from Everything in variables that remain accessible until Opus is closed. Opus receives an update on every folder change if the EverythingFolderSize column is displayed in the file display. This update feature can be disabled using the button provided below. Useful, if you experience decreased performance when opening many tabs via Layouts or Tabgroups. If disabled, the column will continue to display the last received values, and changes will not be reflected. It's worth noting that if the column doesn't receive valid data from Everything, it will remain empty.
It's important to keep in mind that both Opus and Everything cache folder sizes. While refreshing these caches is typically fast, it's crucial to check with Opus' internal functions before performing any critical actions, such as deletion, based on the values in the column.
function OnInit(initData) {
initData.name = 'EverythingFolderSize';
initData.version = '2023-05-02';
initData.copyright = '';
initData.url = 'https://resource.dopus.com/t/everythingfoldersize-use-everything-to-calculate-folder-sizes/44281';
initData.desc = '';
initData.default_enable = true;
initData.min_version = '12.0';
}
function OnAddColumns(addColData) {
var col = addColData.AddColumn();
col.name = 'EverythingFolderSize';
col.header = 'EFS';
// col.label = 'EverythingFolderSize';
col.method = 'OnColumn';
col.justify = 'right';
col.type = 'size';
}
function OnColumn(scriptColData) {
var item = scriptColData.item;
if (!item.is_dir) return;
if (item.path.drive == 0) return;
var dirVar = 'EFS"' + item + '"';
if (!DOpus.vars.Exists(dirVar)) return;
scriptColData.value = DOpus.vars.Get(dirVar);
}
function OnInit(initData) {
initData.name = 'UpdateEverythingFolderSize';
initData.version = '2023-05-02b';
initData.copyright = '';
initData.url = 'https://resource.dopus.com/t/everythingfoldersize-use-everything-to-calculate-folder-sizes/44281';
initData.desc = '';
initData.default_enable = true;
initData.min_version = '12.0';
}
var cmd = DOpus.Create().Command();
var stt = DOpus.Create().StringTools();
var fsu = DOpus.FSUtil();
var wsh = new ActiveXObject('WScript.Shell');
var exeES = fsu.Resolve('/programfiles\\Everything\\es.exe'); // Check "Index folder size" in Tools-Options-Indexes
// var exeES = fsu.Resolve('/programfiles\\Everything 1.5a\\es.exe'); // Everything-1.5a.ini needs to contain this line: alpha_instance=0
if (!fsu.Exists(exeES)) {
DOpus.Output('"' + exeES + '" not found!');
}
function OnBeforeFolderChange(beforeFolderChangeData) {
cmd.SetSourceTab(beforeFolderChangeData.tab);
if (!cmd.IsSet('Set COLUMNSTOGGLE=scp:EverythingFolderSize/EverythingFolderSize')) return;
if (!fsu.Exists(exeES)) return;
var exportFile = fsu.GetTempFilePath();
var cmdLine = '"' + exeES + '"' +
' -size' +
' -no-header' +
' -export-csv "' + exportFile + '"' +
' -parent "' + beforeFolderChangeData.path + '"' +
' /ad';
// DOpus.Output(cmdLine);
wsh.Run(cmdLine, 0, true);
var vec = DOpus.Create().Vector(stt.Decode(fsu.GetItem(exportFile).Open().Read(), 'utf8').split('\r\n'));
var re = /(\d+),(.*)/;
for (var e = new Enumerator(vec); !e.atEnd(); e.moveNext()) {
var line = re.exec(e.item());
if (line == null) continue;
if (line.length != 3) continue;
var size = line[1];
var dirVar = 'EFS' + line[2];
DOpus.vars.Set(dirVar, size);
}
}
How to use
Install Everything (both Everything and Everything Command-line Interface).
Copy es.exe
to /programfiles\Everything
(What are aliases?).
If you run Everything 1.4 check Index folder size in Everything Options.
If you run Everything 1.5a
- copy
es.exe
to/programfiles\Everything 1.5a
- pick the right
var exeES = ...
line in the script - add a line (or change)
alpha_instance=0
inEverything-1.5a.ini
.
Save
ColumnEverythingFolderSize.js.txt
EventUpdateEverythingFolderSize.js.txt
to
%appdata%\GPSoftware\Directory Opus\Script AddIns
Add a button to toggle the column. Refresh the lister once after turning the column on. Typically F5.
Set COLUMNSTOGGLE="scp:EverythingFolderSize/EverythingFolderSize(!,a,0)"
Button as XML
<?xml version="1.0"?>
<button backcol="none" display="label" label_pos="right" textcol="none">
<label>EverythingFolderSize</label>
<icon1>#newcommand</icon1>
<function type="normal">
<instruction>Set COLUMNSTOGGLE="scp:EverythingFolderSize/EverythingFolderSize(!,a,0)"</instruction>
</function>
</button>
Optional: Add a button to toggle the event that updates the folder size cache. Only needed if you run into problems.
@toggle:invert
Prefs SCRIPTDISABLE="EventUpdateEverythingFolderSize.js*,toggle"
Button as XML
<?xml version="1.0"?>
<button backcol="none" display="both" label_pos="right" textcol="none">
<label>UpdateEverythingFolderSize</label>
<icon1>#filterfolder</icon1>
<function type="normal">
<instruction>@toggle:invert</instruction>
<instruction>Prefs SCRIPTDISABLE="EventUpdateEverythingFolderSize.js*,toggle"</instruction>
</function>
</button>
Older versions:
2023-04-25
EventUpdateEverythingFolderSize.js.txt
ColumnEverythingFolderSizeVars.js.txt
works in Flatview, but much slower:
ColumnEverythingFolderSize.js.txt