Hello, would like an bit of advice.
Want to try to get sorting by portion of filename.
Here are name examples:
SomeText.23.05.19.Additional.Text
SomeText.23.04.19.Additional.Text
SomeText.23.03.19.Additional.Text
Text - 2023.05.19 - Additional - Text
Text - 2023.04.19 - Additional - Text
Text - 2023.03.19 - Additional - Text
Found this code, and managed to install it.
The filenames are in the format "somealphatext nnnnn_xxx", where I want to sort by "xxx".
function OnInit(initData){
initData.name = "PnNumber";
initData.desc = "Add a sortable column for pn number";
initData.copyright = "myarmor";
initData.…
While it says that code should detect numbers, and show these in added column, I get "No Number" result.
Tried to adjust regex pattern with GPT help but no luck. What important details I'm missing?
lxp
December 16, 2023, 6:46pm
2
Your digits look more like dates. Which numbers do you want to extract?
I would like to grab these dates.
Tried this one, but script with such pattern returns still "No Numbers."
lxp
December 16, 2023, 6:52pm
4
Did you change the underscores to dots?
Sounds like an hint, probably I should...
/^\w+ \d+[.](\d+)/i
same bahavior.
Should I restart DO, so changes to JS are applied? Or its enough to remove column and enable it again.
lxp
December 16, 2023, 6:59pm
6
Simply saving the edited script is enough. Maybe a file display refresh.
lxp
December 16, 2023, 7:06pm
7
The regex should probably look more like this (with three capture groups):
var re=/.*(\d+)\.(\d+)\.(\d+).*/;
No luck still.
Initial script, it works for you?
I'm on DO13. Doubt that it breaks certain stuff.
lxp
December 16, 2023, 7:42pm
9
I haven't tried the script
If you already run v13 use an evaluator column, they are made for this problem and are much easier!
Grabbed these scripts to see if these work.
This is a script I made for a friend who has a huge movie collection. He wanted to keep track of movie's directors, countries and a few other fields. He bought Opus just for this script. I thought it was so cool I had to perfect it and share it.
Thi…
There are plenty options.
But one I tried - Movie.Year should show an year from metadata, aaaaaand its column is also empty.
Will check evaluator thing. Hear these terms, but was never interested in it. Guess maybe its good time to do.
lxp
December 16, 2023, 7:52pm
11
Try
yy = RegEx(name,".*?(\d+)\.(\d+)\.(\d+).*","\1");
mm = RegEx(name,".*?(\d+)\.(\d+)\.(\d+).*","\2");
dd = RegEx(name,".*?(\d+)\.(\d+)\.(\d+).*","\3");
if (yy<100) yy += 2000;
return (yy + "-" + mm + "-" + dd) as date;
Go to
Prefs PAGE="evalcolumns"
and paste this
XML
<?xml version="1.0"?>
<evalcolumn align="0" attrrefresh="no" autorefresh="no" foldertype="all" keyword="t47486" maxstars="5" namerefresh="no" reversesort="no" title="t47486" type="0">yy = RegEx(name,".*?(\d+)\.(\d+)\.(\d+).*","\1");
mm = RegEx(name,".*?(\d+)\.(\d+)\.(\d+).*","\2");
dd = RegEx(name,".*?(\d+)\.(\d+)\.(\d+).*","\3");
if (yy<100) yy += 2000;
return (yy + "-" + mm + "-" + dd) as date;</evalcolumn>
1 Like
Yes, this does work.
Thanks a lot, took me a while to find where to even search for these columns.
Just an slight update.
Script refused to show dates for YYYY.MM.DD format.
So far had to edit script to this:
yy = RegEx(name,".*?(\d{2}|\d{4}).(\d+)\.(\d+)\.*","\1");
Now it detects 4digit date, but grabs first two numbers.
Swapping 2 and 4, again makes values to disappear.
lxp
December 17, 2023, 5:11am
14
Try
yy = RegEx(name,".*?(\d+)\.(\d+)\.(\d+).*?","\1");
mm = RegEx(name,".*?(\d+)\.(\d+)\.(\d+).*?","\2");
dd = RegEx(name,".*?(\d+)\.(\d+)\.(\d+).*?","\3");
if (yy<100) yy += 2000;
return (yy + "-" + mm + "-" + dd) as date;
2 Likes
Yup, works. Thanks a lot.
lxp
January 3, 2024, 7:13am
16
This column has benefitted from a bug (automatic type conversion) that was corrected in 13.0.55 .
We now need to explicitly convert the string to an integer and change the code accordingly:
yy = RegEx(name,".*?(\d+)\.(\d+)\.(\d+).*?","\1") As int;
mm = RegEx(name,".*?(\d+)\.(\d+)\.(\d+).*?","\2");
dd = RegEx(name,".*?(\d+)\.(\d+)\.(\d+).*?","\3");
if (yy<100) yy += 2000;
return (yy + "-" + mm + "-" + dd) As date;
5 Likes