How do you sort items without sorting them?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

How do you sort items without sorting them?

Post by bdeshi »

:veryconfused:

Is there any way to retrieve the itemlist sorted by some criteria, without actually applying the sort-order to the list pane?
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

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

Re: How do you sort items without sorting them?

Post by highend »

Define criteria :)

formatlist() but only for common type(s)
One of my scripts helped you out? Please donate via Paypal

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: How do you sort items without sorting them?

Post by bdeshi »

criteria are the usual column sort options: date, name, size etc.
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

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

Re: How do you sort items without sorting them?

Post by highend »

An example for size:

Code: Select all

    $items = folderreport("files:{size RAW}|{fullname}", "r", , , , "<crlf>");
    $items = formatlist($items, "n", "<crlf>");
    $items = regexreplace($items, "^(\d+\|)(.*)", "$2");
    text $items;
Works the same for date and name can be done by formatlist without any folderreport() / regexreplace()
One of my scripts helped you out? Please donate via Paypal

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: How do you sort items without sorting them?

Post by bdeshi »

Brilliant! :tup:

(although a builtin command to return such sorted list would be nice and easier to use)
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

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

Re: How do you sort items without sorting them?

Post by highend »

Build your own and make a sort function out of it :)

Like:

Code: Select all

    text sortFiles(, "created", "d");

/*
$path     = For which part to report (default = "<curpath>")
$criteria = size (default) | created (date) | modified (date)
$order    = "a" (ascending, default), "d" (descending)
$flags    = "r" (default) -> recursive or ""
$delim    = How should the output be delimited (default = "new line")
*/
function sortFiles($path = "<curpath>", $criteria = "size", $order = "a", $flags = "", $delim = "<crlf>") {
    if ($criteria LikeI "size") { $criteria = "size RAW"; }
    elseif ($criteria LikeI "created") { $criteria = "created yyyymmddhhnnss"; }
    elseif ($criteria LikeI "modified") { $criteria = "modified yyyymmddhhnnss"; }
    if ($order LikeI "a") { $order = "n"; }
    elseif ($order LikeI "d") { $order = "nr"; }

    $items = folderreport("files:{$criteria}|{fullname}", "r", "$path", "$flags", , "<crlf>");
    $items = formatlist($items, "$order", "<crlf>");
    $items = regexreplace($items, "^(\d+\|)(.*)", "$2");
    return regexreplace($items, "\r?\n", $delim);
}
One of my scripts helped you out? Please donate via Paypal

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: How do you sort items without sorting them?

Post by bdeshi »

That's one way to go about it.
XYScripting gives you a hammer, ... but that doesn't mean a screwdriver becomes useless. :wink:
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

Post Reply