Fault tolerant renaming of a file.


      RenameFile(<cOldFileName>, <cNewFileName>) --> <nErrorCode>


<cOldFileName> : The name and path of the existing file. <cNewFileName> : The new name and path for the file.


<nErrorCode> : A 0 when the file can be renamed; otherwise, it returns an error code. The codes are defined below:

          RenameFile() Error Codes
          Code    Definition
           0      No error found
          -2      File not found
          -3      Path not found
          -5      Access denied (e.g., in network)
          -17     Target file not on same network


Currently, you may not be able to rename a file on a network drive. Another user may currently have the file open. RenameFile() actually says “attempt a RENAME and, should the situation arise, return an error code”. This follows the basic programming philosophy: never fall into an error trap when you can avoid it.


. The <cNewFileName> must always contain the complete path for the designated file (see Examples).

. Wildcard characters cannot be used.


      .  Rename a file from OLD to NEW:

         IF RenameFile("OLD", "NEW") = 0
            ? "The file is renamed!"

      .  Use the path from the old file specification for the new name:

         cFSpecOld   := "C:\TEST\TEST.TXT"
         cFileName   := TOKEN(cFSpecOld, ":\")      // last token
         cFSpecNew   := BEFOREATNUM(cFileName, cFSpecOld) + "TEST.NEW"
         RenameFile(cFSpecOld, cFSpecNew)

See also


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s