FUNCTIONS CORE

RenameFile()

Rename a file and handle errors

Syntax

Signature
RenameFile( cOldFile, cNewFile ) --> nErrorCode

Arguments

cOldFile

cNewFile

Example

RenameFile.prg
PROCEDURE Main()

   LOCAL lText := MemoWrit( "old.txt", "xDev", .F. )

   Check( 'RenameFile( "old.txt", "new.txt" )  ', RenameFile( "old.txt", "new.txt" ), 0 )
   Check( 'File( "new.txt" )                   ', File( "new.txt" ), .T. )
   Check( 'RenameFile( "old.txt", "new2.txt" ) ', RenameFile( "old.txt", "new2.txt" ), -2 )
   Check( 'FErase( "new.txt" )                 ', FErase( "new.txt" ), 0 )

RETURN

STATIC PROCEDURE Check( cTitle, xResult, xExpected )

   QOut( cTitle + IIF( xResult == xExpected, "OK", "ERROR" ) )

RETURN

Output

RenameFile( "old.txt", "new.txt" )  OK
File( "new.txt" )                   OK
RenameFile( "old.txt", "new2.txt" ) OK
FErase( "new.txt" )                 OK