PathDepth (Display depth in folder hierarchy)

This script column PathDepth displays the depth of files and folders in the folder hierarchy. Items on the root level (e.g. in C:\) have level 1. Useful in filters and for sorting and grouping in Flatview.

function OnInit(initData) { = 'PathDepth';
    initData.version = '2022-11-03';
    initData.copyright = '';
    initData.url = '';
    initData.desc = 'Display path depth.';
    initData.default_enable = true;
    initData.min_version = '12.0';

function OnAddColumns(addColData) {
    var col = addColData.AddColumn(); = 'PathDepth';
    col.method = 'OnColumn';
    col.justify = 'right';
    col.type = 'number';

function OnColumn(scriptColData) {
    scriptColData.value = scriptColData.item.path.components;


How to use buttons and scripts from this forum

In Opus v13 a simple Eval column can replace the script column:


evalcolumn as XML
<?xml version="1.0"?>
<evalcolumn align="1" attrrefresh="no" autorefresh="no" foldertype="all" keyword="PathDepth" maxstars="5" namerefresh="no" reversesort="no" title="PathDepth" type="2">Count(path)</evalcolumn>

scriptColData.item.path.Split().count = scriptColData.item.path.components?

Yes. The property probably needs less computing power, which is always welcome. Thanks!

Super script and ideas. Thank You

How would I get the path depth from this to use in a simple conditional in a button on the order of: If pathdepth = 1 then display a message? I'm interested in how to do the if clause. Can I do this without the column being displayed? Thanks for any help.

@lxp As always, thanks for posting helpful scripts! Looking at path depth from the opposite angle, how might one calculate depth from the current directory to component(s) within the deepest subfolder?

That's a job for the Evaluator in v13 :slight_smile:

If you already have the deepest subfolder it's basic calculus. Finding the deepest subfolder is a bit trickier. Are you looking for the absolute deepest subfolder or the first folder that doesn't contain another folder?

Looking for absolute deepest folder. Example:

Deepest Filepath = Root\F1\F2\F3...\Fn\component

If F3 is displayed in lister, then PathDepth = 4 and AbsoluteDepth = Fn + 1

You would need to completely enumerate F3, get the path depth of all folders, and keep the folder with the maximum number. Certainly doable, but displaying the results in columns might get a bit slow on large HDDs with a big folder tree.

Thanks for confirming my suspicion. Not sure the result is worth the effort given some extensive folder trees I manage and other non-DO tools at hand.