跳转到内容

Rebol 编程/change-dir

来自维基教科书,开放世界中的开放书籍
CHANGE-DIR dir 

更改活动目录路径。

CHANGE-DIR 是一个函数值。

  • dir -- 新目录路径 (类型:文件)

(特殊属性)

[编辑 | 编辑源代码]
  • 捕获

源代码

[编辑 | 编辑源代码]
change-dir: func [
    "Changes the active directory path." 
    [catch] 
    dir [file!] "new directory path" 
    /local slash full ret
][
    dir: clean-path dir 
    if (last dir) <> #"/" [append dir #"/"] 
    if (first dir) = #"/" [
        slash: next dir 
        full: remove parse system/script/path "/" 
        while [all [not empty? slash (first slash) = #"/" not empty? full]] [
            insert slash first full 
            remove full 
            slash: find/tail slash "/" 
            if (empty? full) or (empty? slash) [clear slash break]
        ]
    ] 
    either throw-on-error [dir? dir] [
        system/script/path: dir
    ] [
        throw make error! reduce ['access 'cannot-open dir]
    ] 
    system/script/path
]
华夏公益教科书