Sign in Join
FPDoc Onlineexperiment

RenameFile function

In unit sysutils

Rename a file.

Declaration

pascal
function RenameFile(const OldName: UnicodeString; 
 const NewName: UnicodeString): 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

Example: ex44

pascal
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.

An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.