[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] Reference for unit 'sysutils' (#rtl)

RenameFile

Rename a file.

Declaration

Source position: filutilh.inc line 136

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 undelying OS's support for renaming/moving a file. Whether or not a file can be renamed accros disks or partitions depends entirely on the OS. On unix-like OS-es, the rename function will fail when used accross partitions. On Windows, it will work.

Errors

On Error, False is returned.

See also

DeleteFile

  

Delete a file from the filesystem.

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.

Documentation generated on: Mar 17 2017