Command ERASE Foundation

Deletes a file from a hard disk or diskette.

Syntax
ERASE <cFileName> | DELETE FILE <cFileName>
Parameters
<cFileName>
<cFilename> specifies the name of the file to delete. The name must contain the drive and path if they are necessary. It can be specified as either a literal file name or as a character expression in parentheses.
Description

The file command ERASE deletes a file from hard disk or diskette. DELETE FILE can be used instead of ERASE. Both commands delete a file. The file is only deleted if <cFilename> is a valid file name. Failure of the deletion operation can be detected by the error code returned from the function FError().

The command does not consider either the setting set with PATH or the path specified with DEFAULT. <cFilename> must be a complete file name, including drive and path. If no drive or path is contained in <cFilename>, ERASE searches for the file in the current path.

The function FErase() is the functional equivalent of the command ERASE.

Before a file can be deleted, it must first be closed if it is open.

Under OS/2, the deleted file can be recovered using the UNDELETE command when the environment variable SET DELDIR= is defined in CONFIG.SYS.

Examples
ERASE
// The example shows the various ways to call ERASE. 

PROCEDURE Main 
   LOCAL cFileName := "Test1.txt" 

   ERASE ( cFileName )   // specify using a variable 

   ERASE Test2.txt       // literal file name 

   IF FError() <> 0 
      ? "Error deleting file:",FError() 
   ENDIF 
RETURN 
Delete files by groups
// In this example, all NTX files in the current directory 
// are found using Directory(). Then all NTX files 
// are deleted with ERASE. 

#include "Directry.ch" 

PROCEDURE Main 
   LOCAL aDirectory := Directory("*.NTX"), n, nCount 
   nCount := Len( aDirectory ) 

   FOR n:=1 TO nCount 
      ERASE ( aDirectory[n, F_NAME] ) 
   NEXT 
RETURN 

Feedback

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.