[REBOL] Re: Simple sorting
From: carl:cybercraft at: 27-Sep-2002 20:12
I was sure sort/compare could be used, so I tried again and came up
dir-sort: func [a b][
either any [
all [#"/" = last a #"/" = last b]
all [#"/" <> last a #"/" <> last b]
a < b
#"/" = last a ; Change to b to place files first.
; To test...
dir: %./ ; Current directory.
result: sort/compare read dir :dir-sort
It'll fall over if there's a file without any characters to its name,
(is that likely to exist on any systems?), but otherwise it seems to
On 27-Sep-02, Anton wrote:
> You could also do it like this,
> which does not use dir? and does not
> use any extra functions:
> dir: %./ ; current directory
> result: copy 
> dirs: copy 
> files: copy 
> foreach file read dir [
> append either #"/" = last file [dirs][files] file
> result: compose [(sort dirs) (sort files)]
> I have found it handy to have the files and dirs
> in separate blocks for other processing, so that
> may make this way preferable.
>> << How do I get the code, listing: sort read %., to sort
>> alphabetically by directories first then by filenames? So, the
>> result looks like this: [%dir1/ %dir2/ %dir3/ %file1 %file2 %file3]