RENAME Command
Changes the name of a file to a new name.
Note
Do not use RENAME to change the name of a table in a database; RENAME does not change the name of the table in the database. Instead, use RENAME TABLE to change the name of a table in a database. For more information, see RENAME TABLE Command.
RENAME FileName1 TO FileName2
Parameters
FileName1 TO FileName2
Specifies the file name to change and the new file name. Include a file extension for each file.Note
If the file extensions are not included, the default extension .dbf is assumed. To rename a file that does not have an extension, include a period (.) after the file name. If you rename a free table that has an associated .fpt memo file, be sure to rename the memo file.
Remarks
FileName1 and FileName2 can contain wildcard characters such as * and ?. For example, to rename all program files with the extension .prg in the current directory or folder to backup files with extension .bak, issue RENAME *.prg TO *.bak.
If the files are not on the default path, include paths with either or both file names.
If FileName1 and FileName2 are in different directories or folders, FileName1 is moved into the directory or folder of FileName2.
When you issue RENAME, FileName2 cannot already exist and FileName1 must exist and cannot be open.
Example
The following example shows how to switch file names between two files. Visual FoxPro will generate an error if you attempt to rename a file to a name which already exists (this is shown by the Try…Catch statement). The example uses multiple RENAME calls with an extra temporary file to accomplish the name switching.
STRTOFILE("File 1", "tmpFile1.txt")
STRTOFILE("File 2", "tmpFile2.txt")
TRY
RENAME tmpFile1.txt TO tmpFile2.txt
CATCH TO oError
? oError.Message
ENDTRY
RENAME tmpFile2.txt TO tmpFile2.bkup
RENAME tmpFile1.txt TO tmpFile2.txt
RENAME tmpFile2.bkup TO tmpFile1.txt
MODIFY FILE tmpFile1.txt NOWAIT
MODIFY FILE tmpFile2.txt NOWAIT