Split path

angerangel edited this page Jan 7, 2013 · 1 revision
Clone this wiki locally

USAGE

   SPLIT-PATH target

DESCRIPTION

Splits and returns directory path and file as a block.

SPLIT-PATH is a function value.

ARGUMENTS

  • target (file! url! string!)

#SOURCE

split-path: make function! [  [
    {Splits and returns directory path and file as a block.}
    target [file! url! string!]
    /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]
] ]