Page 1 of 1

How do you sort items without sorting them?

Posted: 16 Jan 2016 12:31
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?

Re: How do you sort items without sorting them?

Posted: 16 Jan 2016 12:42
by highend
Define criteria :)

formatlist() but only for common type(s)

Re: How do you sort items without sorting them?

Posted: 16 Jan 2016 12:46
by bdeshi
criteria are the usual column sort options: date, name, size etc.

Re: How do you sort items without sorting them?

Posted: 16 Jan 2016 12:56
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()

Re: How do you sort items without sorting them?

Posted: 16 Jan 2016 12:58
by bdeshi
Brilliant! :tup:

(although a builtin command to return such sorted list would be nice and easier to use)

Re: How do you sort items without sorting them?

Posted: 16 Jan 2016 13:30
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);
}

Re: How do you sort items without sorting them?

Posted: 16 Jan 2016 18:04
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: