List dir

angerangel edited this page Jan 4, 2013 · 1 revision

USAGE

   LIST-DIR 'path /l /f /d /r /i indent

DESCRIPTION

Print contents of a directory (ls).

LIST-DIR is a function value.

ARGUMENTS

  • path -- Accepts %file, :variables, and just words (as dirs) (file! word! path! string! unset!)

REFINEMENTS

  • /l -- Line of info format
  • /f -- Files only
  • /d -- Dirs only
  • /r -- Recursive
  • /i
    • indent

#SOURCE

list-dir: make function! [  [
    "Print contents of a directory (ls)."
    'path [file! word! path! string! unset!] {Accepts %file, :variables, and just words (as dirs)}
    /l "Line of info format"
    /f "Files only"
    /d "Dirs only"
    /r "Recursive"
    /i indent
    /local files save-dir info
][
    save-dir: what-dir
    switch type?/word :path [
        unset! []
        file! [change-dir path]
        string! [change-dir to-rebol-file path]
        word! path! [change-dir to-file path]
    ]
    if r [l: true]
    unless l [l: make string! 62]
    unless indent [indent: ""]
    files: attempt [read %./]
    if not files [print ["Not found:" :path] change-dir save-dir exit]
    foreach file files [
        if any [
            all [f dir? file]
            all [d not dir? file]
        ] [continue]
        either string? l [
            append l file
            append/dup l #" " 15 - remainder length? l 15
            if greater? length? l 60 [print l clear l]
        ] [
            info: get query file
            change info second split-path info/1
            printf [indent 16 -8 #" " 24 #" " 6] info
            if all [r dir? file] [
                list-dir/l/r/i :file join indent "    "
            ]
        ]
    ]
    if all [string? l not empty? l] [print l]
    change-dir save-dir
    exit
] ]
Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.