Rebol Programming/cd

From Wikibooks, open books for an open world
Jump to navigation Jump to search

USAGE:[edit | edit source]

CD 'path 

DESCRIPTION:[edit | edit source]

Change directory (shell shortcut function).

CD is a function value.

ARGUMENTS[edit | edit source]

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

(SPECIAL ATTRIBUTES)[edit | edit source]

  • catch

SOURCE CODE[edit | edit source]

cd: func [
    "Change directory (shell shortcut function)." 
    [catch] 
    'path [file! word! path! unset! string! paren!] "Accepts %file, :variables and just words (as dirs)"
][
    if paren? get/any 'path [set/any 'path do path] 
    switch/default type?/word get/any 'path [
        unset! [print what-dir] 
        file! [change-dir path] 
        string! [change-dir to-rebol-file path] 
        word! path! [change-dir to-file path]
    ] [throw-error 'script 'expect-arg reduce ['cd 'path type? get/any 'path]]
]