RenameFile()

Summary

Copies, moves, or changes the name of a file.

Syntax

RenameFile(string source_file, string dest_file)

Argument Contents
source_file The source file name
dest_file The destination file name

Notes

  • If dest_file has no drive and folder then it is renamed in the same drive and folder as source_file; if dest_file has no drive or the same drive but a different folder then it is moved to that folder; otherwise source_file is copied to the drive and folder specified by dest_file.

  • dest_file must not already exist.

Examples

RenameFile("c:\\Temp\\x.txt", "y.txt") // The new file name is c:\Temp\y.txt
RenameFile("c:\\Temp\\x.txt", "\\Stuff\\x.txt ") // The file is moved to the Stuff folder
RenameFile("c:\\Temp\\x.txt", "a:\\x.txt ") // The file is copied to the a: drive

Error Codes

Error Type Meaning
Error dest_file already exists.
NotFound source_file does not exist

See Also

Function Summary
CopyFile() Copies a file
DeleteFile() Deletes a file