跳转到内容

Rebol 编程/delete

来自维基教科书,开放世界中的开放书籍
DELETE target /any 

删除指定的文件。

DELETE 是一个函数值。

  • 目标 -- 要删除的文件(类型:文件 URL)
  • /any -- 允许通配符

(特殊属性)

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

源代码

[编辑 | 编辑源代码]
delete: func [
    "Deletes the specified file(s)." 
    [catch] 
    target [file! url!] "the file to delete" 
    /any "allow wild cards" 
    /local p dir blk file ret err
][
    dir: throw-on-error [open first p: split-path clean-path target] 
    error? set/any 'err try [
        either any [
            blk: copy dir 
            foreach file blk [
                ret: find/match/any file second p 
                if none? ret [ret: file] 
                either tail? ret [
                    remove dir
                ] [
                    dir: next dir
                ]
            ]
        ] [
            blk: copy dir 
            either not none? blk: find blk second p [
                remove skip dir (index? blk) - 1
            ] [
                make error! reduce ['access 'no-delete target]
            ]
        ]
    ] 
    attempt [close dir] 
    either error? get/any 'err [throw err] [get/any 'err]
]
华夏公益教科书