Command RENAME Foundation
Changes the name of a file.
RENAME <cOldName> TO <cNewName>
The file command RENAME renames a file. The file is renamed only when <cOldFile> and <cNewFile> contain valid file names. If the operation fails, the file error can be determined using the error code returned by the function FError().
The command does not consider either the PATH setting or the path specified with DEFAULT. <cOldName> and <cNewName> must be complete file names including the drive and path. When the file name does not contain drive or path, the current directory is searched for <cOldName>.
If the original directory is not the same as the target directory, the file is moved to the target directory. If a file already exists with the file name <cNewName>, RENAME fails.
The functional equivalent of the command RENAME is the function FRename().
// In the example, a DBF file and its memo file are renamed,
// showing different ways to call the RENAME command.
PROCEDURE Main
LOCAL cOldMemoFile := "CUST.DBT"
LOCAL cNewMemoFile := "CUSTOMER.DBT"
? File( "CUST.DBF" ) // result: .T.
? File( cOldMemoFile ) // result: .T.
RENAME Cust.dbf TO Customer.dbf // literal file name
RENAME (cOldMemoFile) TO (cNewMemoFile) // specify using variables
? File( "CUST.DBF" ) // result: .F.
? File( cOldMemoFile ) // result: .F.
RETURN
// The example shows a user defined command which renames
// DBF files and the corresponding memo file if it exists.
// The file names, but not the file extensions, are specified.
#command RENAME DBF <(OldFile)> TO <(NewFile)> ;
=> ;
IF File(<(OldFile)>+".DBF") ;;
RENAME (<(OldFile)>+".DBF") TO (<(NewFile)>+".DBF") ;;
IF FError()==0 .AND. File(<(OldFile)>+".DBT") ;;
RENAME (<(OldFile)>+".DBT") TO (<(NewFile)>+".DBT") ;;
ENDIF ;;
ENDIF
PROCEDURE Main
? File( "CUST.DBF" ) // result: .T.
? File( "CUST.DBT" ) // result: .T.
RENAME DBF Cust TO Customer
? File( "CUST.DBF" ) // result: .F.
? File( "CUST.DBT" ) // result: .F.
? File( "CUSTOMER.DBF" ) // result: .T.
? File( "CUSTOMER.DBT" ) // result: .T.
RETURN
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.