跳至內容

Rebol 程式設計/split-path

來自華夏公益教科書,開放書籍,面向開放世界
SPLIT-PATH target 

拆分檔案或 URL 路徑。返回一個包含路徑和目標的塊。

SPLIT-PATH 是一個函式值。

  • target -- (型別:檔案 url)

原始碼

[編輯 | 編輯原始碼]
split-path: func [
    {Splits a file or URL path. Returns a block containing path and target.} 
    target [file! url!] 
    /local dir pos
][
    parse/all target [
        [#"/" | 1 2 #"." opt #"/"] end (dir: dirize target) | 
        pos: any [thru #"/" [end | pos:]] (
            all [empty? dir: copy/part target at head target index? pos dir: %./] 
            all [find [%. %..] pos: to file! pos insert tail pos #"/"]
        )
    ] 
    reduce [dir pos]
]
華夏公益教科書