RENAME Function (File)

Renames an ASCII or binary file.

[Ok :=]RENAME(OldName, NewName)

Parameters

  • OldName
    Type: Text or Code. The current name of the file that you want to change, including its path. When you enter the path, consider these shortcuts:
    • You can omit the drive designation, if the file is located on the current drive.

    • You can omit the full path, if the file is located in the current directory.

    • You can enter only the subdirectory name, if the file is located in a subdirectory of the current directory.

  • NewName
    Type: Text or Code The new name that you want to assign to the file, including its path. When you enter the path, consider these shortcuts:
    • You can omit the drive designation, if the file is located on the current drive.

    • You can omit the full path, if the file is located in the current directory.

    • You can enter only the subdirectory name, if the file is located in a subdirectory of the current directory.

Property Value/Return Value

Type: Boolean

If you omit this optional return value, a run-time error occurs when the file cannot be found. When you include the return value, it is assumed that you will handle any errors.

true if the file was renamed; otherwise, false.

Remarks

Typically the return value is false if the file does not exist, or if the file is a system or hidden file.

Example

The following example changes the name of a text file that is named Testfile.txt to NewTestFile.txt. The path of the file that is renamed is C:\TestFolder\Testfile.txt. The name and path are stored in the varOldFile variable. The new name and path of the file are stored the varNewfile variable. The RENAME function uses the variables to change the name of the file. This example assumes that you have created the following file on your computer: C:\TestFolder\Testfile.txt. This example requires that you create the following variables in the C/AL Globals window.

Variable name DataType

varOldfile

Text

varNewfile

Text

varOldfile := 'C:\TestFolder\Testfile.txt' ;
varNewfile := 'C:\TestFolder\NewTestFile.txt';
RENAME(varOldfile, varNewfile);

See Also

Reference

File Data Type