Feature suggestion: Columns based on regex-ed filename

Not really sure if anyone has suggested this or something similar before as a forum search yielded no relevant topics. So here is the deal:

I'm often in a situation where I have many machine generated files in a folder with names like:[0000-00-00][12345] Some Name [PID_123]
Regex-coloring of files works great but if I want to sort by a specific code or identifier I have to rename all files with a script and a different one at that, for each property I want to sort or group by. And no using filters does not help with sorting.

The ability to add custom columns (in details view) based on a simple regex of the filename would allow me to do this:
Variant 1: Each custom column does it's own regex matching against the filename

\[(PID_\d*)] -- Column gets the value of backreference one which is the pid \[(\d*)\] -- Column gets the numeric id value and so on.
Variant 2: Single regex with named capturing groups and each named group appears as a custom column:

\[(?P<Date_col>\d{4}-\d{2}-\d{2})]\[(?P<Index_col>\d*)\] (?P<Name_col>[\w\s]*)\[(?P<Pid_col>PID_\d*)\]

Variant 1 would allow more flexibility when regexing "unlike filenames" not having the same pattern but would be taxing if we have too many such columns defined.
Variant 2 would be faster but would only work on filenames which have the exact schema so the ability to specify multiple reg-exes would be a good thing as well.
IMO the ability to specify multiple sets of such columns and to limit queries to specific folders would be useful in the long run.
Since Dopus is already doing heavy regexing for the color labels and there is no perceived performance hit whatsoever I figured it wouldn't be a problem performance-wise.

I am interested if anyone finds this to be a useful feature as I do and if the cost of implementing it would be too high for it not to appear in the next major dopus revision. Thank you.

I like the idea. I suggested a possible Custom Sort feature request somewhere.

Does TR1 Regex allow named captures? I didn't think so, so probably variant 2 is not likely.

Good point MrC.
I only listed some possible solutions and haven't actually thought about TR1's limitations. Indeed it seems quite primitive when compared to full blown PCRE.
Keeping that in mind we could either bind numbered groups to custom field names - dictionary style, or wait for the GPSoft team to implement a new reg-ex engine like boost or something similar.

Using the new custom column feature in Dopus 11.5.1 you can now do this.

This post will be of interest to you, Custom Column - "Custom Text Columns".

Amazing stuff. I only scanned the latest changelog and saw mostly fixes and this feature somehow escaped me. Many thanks for bringing that up and kudos for the example script.

Hi Apocalypse,

For fun, made a quick version of RegexColumnsReloaded for your files.


ApocalypseColumns.js.txt (10.8 KB)

Ever since seeing wowbagger's script I've been a convert to regex columns. This one that I made has some built-in features that you might like since, like me, you're probably not a fan of JS regex (just about the worst regex flavor in the world)

The column defs took two seconds (just dumped your regex):

'PID' :    { 
    pattern: /\[(PID_\d*)]/,
    group: 1
    },

'numid' :    { 
    pattern: /\[(\d*)\]/,
    group: 1
    },

The group property for the capture group is optional (defaults to 0) but there are a number of other properties (see the defining columns section of the tutorial.

For instance, returnTheFirstNonEmptyGroup helps overcome the lack of lookbehind in JS. There are a number of cool tricks possible.

You might have moved on to bigger and better things but I had nothing better to do. :slight_smile:
If you have suggestions I'd love to hear from another regex lover.


Hey there playful. I'm both humbled and proud that you named the script after me :smiley:
Indeed I've been using a self-modified version of wowbaggers' script since then while adding some properties like { //Description: Represent rating as a star rating //Sample filename: "variable ★8 variable" name: "Rating", re: /★([1-8])/, rep: 1, max: 8, type: "stars", matchType: "file" }, { //Description: Extract date from filename //Sample filename: "variable [2014-09-28] variable" name: "Date", re: /(\d{4}-\d{2}-\d{2})/, type: "date", justify: "right" }
rep == group in my case (if 0 - whole match is returned)
so nothing fancy to write home about. Seeing as how Opus has evolved to allow us to inspect properties and paths now means I need to take another look and re-evaluate how things are done.
Back then I hit a dead end with the column group ordering and it put me off from further digging.

Your script is clean and scalable and is a good foundation for future expansion and I salute you for your contribution towards improving the dopus experience :thumbsup:

Hey man thanks for your encouragements, that put a smile on my face. :slight_smile:
I remember loving your Search Everything plug-in way back when!
As you can see my script is dead simple inside, you and others are making amazing and complex things. I just happen to love regex and this whole idea of parsing file names and making columns, otherwise I leave scripting to the big boys.

Can I please ask a couple questions:

  • What your "max" property do?
  • What does "matchType" do? A check against is_dir to restrict the column to files or folders? I like that idea, will add "fileOnly" and "dirOnly" to RegexColumnsReloaded tomorrow.

Exactly! matchType matches file or dir or both if unspecified:

if (scriptColData.item.is_dir && config.matchType == "file") return; else if (!scriptColData.item.is_dir && config.matchType == "folder") return;
I use Max in special fields like graph and star rating. In graph's case I calculate the step intervals based on it.

        if (column.type == "stars") {
            cmd.maxstars = config.max;
        }

        if (column.type == 'graph') {
            var percentile = 100 / config.max;
            scriptColData.value= result[1] * percentile;
        }

Added dirOnly and fileOnly to restrict the column to files or to dirs.
To use, in a column def, just add dirOnly: true

ApocalypseColumns.js.txt (11.8 KB)

Haha, looks like we posted within second of each other. :slight_smile:
Hey max is useful too, I'll work on that tomorrow.

Hey man, it was really dumb of me to post another version of ApocalypseColumns last night, seeing that you're the master and have already put all kinds of bells and whistles into your column script. That's what I get for doing computer stuff at midnight. :blush:

But your features are terrific and today I added these ideas to RegexColumnsReloaded (three new properties: fileOnly, dirOnly, fullCupValue). Love it... Thank you so much.

PM is disabled but if you have other cool features you can think of for a column script parsing file names, I'd love to brainstorm with you, with a view of maintaining and improving that public script. You can reach me through the sites in my sig and I also started a thread in CoffeeShop to discuss file naming conventions.

Cheers!

1 Like