angerangel edited this page Jan 4, 2013 · 1 revision

USAGE

   MKDIR path /deep

DESCRIPTION

Creates the specified directory. No error if already exists.

MKDIR is a function value.

ARGUMENTS

  • path (file! url!)

REFINEMENTS

  • /deep -- Create subdirectories too

#SOURCE

mkdir: make function! [  [
    {Creates the specified directory. No error if already exists.}
    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]
        cause-error 'access 'cannot-open path
    ]
    if any [not deep url? path] [
        create 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] ]
            cause-error 'access 'cannot-open path
        ]
        insert created path
    ]
    path
] ]
Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.