跳轉到內容

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
]
華夏公益教科書