Rebol 编程/split-path
外观
< Rebol 编程
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]
]