Rebol Programming/split-path

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

USAGE:[edit | edit source]

SPLIT-PATH target 

DESCRIPTION:[edit | edit source]

Splits a file or URL path. Returns a block containing path and target.

SPLIT-PATH is a function value.

ARGUMENTS[edit | edit source]

  • target -- (Type: file url)

SOURCE CODE[edit | edit source]

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]
]