跳到内容

Rebol 编程/make-dir

来自维基教科书,开放的书籍,为开放的世界
MAKE-DIR path /deep 

创建指定目录。如果目录已存在,则不会出错。

MAKE-DIR 是一个函数值。

  • path -- (类型: 文件 URL)
  • /deep -- 也创建子目录

(特殊属性)

[编辑 | 编辑源代码]
  • 捕获

源代码

[编辑 | 编辑源代码]
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
]
华夏公益教科书