Page 1 of 1

What's the recommended way to get a filtered list of files in a folder, sorted by date?

Posted: 16 Jan 2024 12:40
by MBaas
There is listfolder() to list files using a filter - but that list only has filenames. I need it for internal purposes only. But if I understand thinghs right, I'd have to display the folder in a pane and then do a listpane(). Or is there another approach?

Actually I just want to get the name of the most recent file - the first one in that list. But maybe that can be achieved more easily?

Re: What's the recommended way to get a filtered list of files in a folder, soarted by date?

Posted: 16 Jan 2024 12:57
by highend
but that list only has filenames
But you need full paths?

There are multiple ways to get what you want via scripting.

So is your script in that folder (to be able to use listpane())?

Re: What's the recommended way to get a filtered list of files in a folder, sorted by date?

Posted: 16 Jan 2024 13:13
by MBaas
I wouldn't need the path, filename is sufficient. And I have opened a tab showing that path.

So...thinking about it (my initial idea was to do all "hidden", but it might be more transparent if I showed the path) - I can even set a filter to get today's file, sort by timestamp and get that list, so I guess I can take it from there. Thanks for asking and kicking off those ideas... :)

Re: What's the recommended way to get a filtered list of files in a folder, soarted by date?

Posted: 16 Jan 2024 13:29
by highend
There isn't any need to do stuff manually to get the file from the current pane...

Code: Select all

    $report = report("{dir 1|0|-1}<:>{modified yyyy-mm-dd hh:nn:ss}|{fullname}<crlf>");
    $report = regexreplace($report, "^1.*(\r?\n|$)"); // Filters out directories
    $report = regexreplace($report, "^\d<:>"); // Remove the rest of the leading part
    $sorted = formatlist($report, "r", <crlf>); // Sort by date ascendingly
    $latest = gettoken(gettoken($sorted, 1, <crlf>), 2, "|"); // Get the first file off the first line
    text $latest;

Re: What's the recommended way to get a filtered list of files in a folder, sorted by date?

Posted: 16 Jan 2024 14:31
by MBaas
wow, that's useful! I wasn't aware such powerful stuff is doable... :tup: