< Rebol Programming
USAGE:
MAKE-DIR path /deep
DESCRIPTION:
Creates the specified directory. No error if already exists.
MAKE-DIR is a function value.
ARGUMENTS:
- path -- (Type: file url)
REFINEMENTS:
- /deep -- Create subdirectories too
(SPECIAL ATTRIBUTES)
- catch
SOURCE CODE
make-dir: func [
{Creates the specified directory. No error if already exists.}
[catch]
path [file! url!]
/deep "Create subdirectories too"
/local dirs end created
][
if empty? path [return path]
if slash <> last path [path: dirize path]
if exists? path [
if dir? path [return path]
return make error! reduce ['access 'cannot-open path]
]
if any [not deep url? path] [
close throw-on-error [open/new path]
return path
]
path: copy path
dirs: copy []
while [
all [
not empty? path
not exists? path
remove back tail path
]
] [
end: any [find/last/tail path slash path]
insert dirs copy end
clear end
]
created: copy []
foreach dir dirs [
path: either empty? path [dir] [path/:dir]
append path slash
if error? try [make-dir path] [
foreach dir created [attempt [delete dir]]
return make error! reduce ['access 'cannot-open path]
]
insert created path
]
path
]
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.