Jump to content

Rebol Programming/rename

From Wikibooks, open books for an open world

USAGE:

[edit | edit source]
RENAME old new 

DESCRIPTION:

[edit | edit source]

Renames a file to a new name.

RENAME is a function value.

ARGUMENTS

[edit | edit source]
  • old -- path to the old file (Type: file url)
  • new -- new name (not a path) (Type: file url string)

(SPECIAL ATTRIBUTES)

[edit | edit source]
  • catch

SOURCE CODE

[edit | edit source]
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
]