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

Discuss and share scripts and script files...
Post Reply
MBaas
Posts: 582
Joined: 15 Feb 2016 21:08

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

Post 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?
Last edited by MBaas on 16 Jan 2024 16:45, edited 1 time in total.
______________________________________________
Happy user ;-)

highend
Posts: 13333
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

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

Post 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())?
One of my scripts helped you out? Please donate via Paypal

MBaas
Posts: 582
Joined: 15 Feb 2016 21:08

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

Post 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... :)
Last edited by MBaas on 16 Jan 2024 16:45, edited 1 time in total.
______________________________________________
Happy user ;-)

highend
Posts: 13333
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

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

Post 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;
One of my scripts helped you out? Please donate via Paypal

MBaas
Posts: 582
Joined: 15 Feb 2016 21:08

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

Post by MBaas »

wow, that's useful! I wasn't aware such powerful stuff is doable... :tup:
______________________________________________
Happy user ;-)

Post Reply