xHarbour Reference Documentation > Function Reference |
Renames a file.
FRename( <cOldFile>, <cNewFile> ) --> nSuccess
The function returns a numeric value. 0 indicates success and -1 is returned for failure. The cause of a failure can be determined using function FError()
The FRename() function changes the name of a file. The file <cOldFile> is searched in the current directory only, unless a full qualified file name including drive and path is specified. Directories specified with SET DEFAULT and SET PATH are ignored by FRename().
If <cNewFile> is specified as a full qualified file name and its directory differs from the one of <cOldFile>, the source file is moved to the new directory and stored under the new file name.
When the new file either exists or is currently open, FRename() aborts the operation. Use the File() function to test for the existence of <cNewFile>.
A file must be closed before attempting to rename it.
See also: | CLOSE, ERASE, FCReate(), FErase(), FError(), File(), RENAME |
Category: | File functions , Low level file functions |
Source: | rtl\philes.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// The example changes the name of an existing Log file // for archival purposes and creates a new Log file PROCEDURE Main LOCAL nLogs, nHandle IF File( "Logfile.txt" ) nLogs := 0 DO WHILE File( "Logfile." + Padl( nLogs, 3, "0" ) ) nLogs ++ IF nLogs > 999 nLogs := 0 EXIT ENDIF ENDDO IF FRename( "Logfile.txt", ; "Logfile." + Padl( nLogs, 3, "0" ) ) == -1 ? "Error renaming file:", FError() ENDIF ENDIF nHandle := FCreate( "Logfile.txt" ) IF FError() == 0 FWrite( nHandle, "Created: " + DtoS(Date()), 17 ) FClose( nHandle ) ENDIF RETURN
http://www.xHarbour.com