跳轉到內容

Rebol 程式設計/重新命名

來自華夏公益教科書,為開放世界提供開放書籍
RENAME old new 

將檔案重新命名為新名稱。

RENAME 是一個函式值。

  • old -- 舊檔案的路徑(型別:檔案 URL)
  • new -- 新名稱(不是路徑)(型別:檔案 URL 字串)

(特殊屬性)

[編輯 | 編輯原始碼]
  • 捕獲

原始碼

[編輯 | 編輯原始碼]
rename: func [
    "Renames a file to a new name." 
    [catch] 
    old [file! url!] "path to the old file" 
    new [file! url! string!] "new name (not a path)" 
    /local p dir blk
][
    dir: open first p: split-path clean-path old 
    blk: copy dir 
    either not none? blk: find blk second p [
        throw-on-error [change skip dir ((index? blk) - 1) new]
    ] [
        throw make error! reduce ['access 'no-rename old]
    ] 
    close dir
]
華夏公益教科書