RenameFile

Rename a file.

Declaration

Source position: filutilh.inc line 188

  function RenameFile(const OldName: UnicodeString; 
                     const NewName: UnicodeString) : Boolean;
  function RenameFile(const OldName: RawByteString; 
                     const NewName: RawByteString) : Boolean;

Description

RenameFile renames a file from OldName to NewName. The function returns True if successful, False otherwise. For safety, the new name must be a full path specification, including the directory, otherwise it will be assumed to be a filename relative to the current working directory. Remark: The implementation of RenameFile relies on the underlying OS's support for renaming/moving a file. Whether or not a file can be renamed across disks or partitions depends entirely on the OS. On unix-like OS-es, the rename function will fail when used across partitions. On Windows, it will work.

Errors

On Error, False is returned.

See also

Name Description
DeleteFile Delete a file from the file system.

Example

Program Example44;
{ This program demonstrates the RenameFile function }
Uses sysutils;
Var F : Longint;
    S : String;
Begin
  S:='Some short file.';
  F:=FileCreate ('test.dap');
  FileWrite(F,S[1],Length(S));
  FileClose(F);
  If RenameFile ('test.dap','test.dat') then
    Writeln ('Successfully renamed files.');
End.