ERASE Command

Erases a file from disk.

ERASE FileName | ? [RECYCLE]

Parameters

  • FileName
    Specifies the file to be erased. Include the path with the file name if the file is on a different drive or directory from the current drive or directory.

    FileName can contain wildcard characters such as * and ?. For example, to erase backup files with ERASE *.BAK. If FileName contains spaces, enclose the entire file name in quotes.

  • ?
    Displays the Delete dialog box, from which you can choose a file to erase.

  • RECYCLE
    Specifies that the file isn't immediately deleted from disk and is placed in the Windows Recycle Bin.

    Caution   Exercise caution when using ERASE. Any file erased with this command cannot be retrieved. You aren't warned before the file is erased, even if SET SAFETY is ON.

This command does not generate an error if the specified file does not exist.

Example

In the following example, the structure of CUSTOMER.DBF and all records in which the country is USA are copied to a table named backup. The data in backup is then copied to a text file, temp, which is opened and then deleted when it is closed.

CLOSE DATABASES
OPEN DATABASE (HOME(2) + 'data\testdata')
USE customer  && Opens customer table

COPY STRUCTURE TO backup
USE backup
APPEND FROM customer FOR country = 'USA'
COPY TO temp TYPE DELIMITED

WAIT WINDOW 'Press Esc to close and erase temp.txt' NOWAIT
MODIFY FILE temp.txt NOEDIT
ERASE temp.txt
? IIF(FILE('temp.txt'),'File not deleted','File deleted')
USE
ERASE backup.dbf

See Also

DELETE FILE | SET SAFETY Command | APPEND FROM Command