Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[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 with this... 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 work. Carl. 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. > Anton. >> << 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] >>>>
-- Carl Read