Rebol3 Code Examplex
Unix/ls
List the contents of a directory, showing files and folders in the current location or a specified path.
Rebol [
title: "Rosetta code: Unix/ls"
file: %Unix-ls.r3
url: https://rosettacode.org/wiki/Unix/ls
]
;; create some directory structure
make-dir/deep %foo/bar
write %foo/bar/1 "11111"
write %foo/bar/2 "2222222"
write %foo/bar/a "aaaaaaaaaa"
write %foo/bar/b "bbbbbbbbbb"
parse [
"List single directory:"
[list-dir %foo/]
"List recursive directory:"
[list-dir/r %foo/]
"Read files from a directory:"
[probe read %foo/bar/]
"Using call:"
[call/shell/wait either system/platform = 'Windows ["dir .\foo\bar"]["ls -la ./foo/bar"]]
][
some [
set title: string! (print as-yellow title)
some [
set test: block! (print mold/only test try test)
]
(print "")
]
]
;; cleanup
delete-dir %foo/Output:
List single directory:
list-dir %foo/
[DIR: c:\Dev\Builder\tree\rebol\Rebol-RosettaCode\tasks\foo\
└───[ 25-Jun-2026 19:03 bar/
List recursive directory:
list-dir/r %foo/
[DIR: c:\Dev\Builder\tree\rebol\Rebol-RosettaCode\tasks\foo\
└───[ 25-Jun-2026 19:03 c:\Dev\Builder\tree\rebol\Rebol-RosettaCode\tasks\foo\bar\
├───[ 25-Jun-2026 19:03 5 1
├───[ 25-Jun-2026 19:03 7 2
├───[ 25-Jun-2026 19:03 10 a
└───[ 25-Jun-2026 19:03 10 b
Read files from a directory:
probe read %foo/bar/
[%1 %2 %a %b]
Using call:
call/shell/wait either system/platform = 'Windows ["dir .\foo\bar"] ["ls -la ./foo/bar"]