EraseFile

See Also: File I/O Commands, CopyFile, File_Exist, Remove_Directory, Set_Directory

Purpose

Deletes one or more disk files

Syntax

EraseFile {file-spec}

Where

What It Does

EraseFile deletes the file(s) identified by {file-spec}. EraseFile will use the current working folder, unless a path is provided as part of file specification. You may use any valid Windows file specification (including wildcard characters).

 

Be extremely cautious with erasefile. DO NOT CALL ERASEFILE WITHOUT ANY ARGUMENTS! Doing so will delete all files in the current working folder without any warning.

 

Example

The sample deletes the file "hello.txt" in the current working folder (since a path is not specified).

EraseFile "hello.txt"

 

Example

The sample deletes all files with the file extension "txt" in the "C:\My Notes" folder.

EraseFile "C:\My Notes\*.txt"

 

Example

The sample deletes the file "notes.txt" in the "C:\My Notes" folder, then checks whether it was successfully deleted. It then notifies the user of the result. The function DeleteFile is written in a generic manner so it can be used with any file.

Function DeleteFile String sFile Returns Boolean

    Boolean bExist

 

    EraseFile sFile

    File_Exist sFile bExist

 

    // this function returns whether the deletion was successful, thus:

    // return False (did not delete) if file still exists and True (did delete) if it does not

    Function_Return (not(bExist))

End_Function

 

Procedure DeleteMyNotes

    String sFile

    Boolean bSuccess

 

    Move "C:\My Notes\Hello.txt" to sFile

    Get DeleteFile sFile to bSuccess

    If (bSuccess) Begin

        Send Info_Box ("The file ' + sFile + "' was deleted successfully" "Success!")

    End

    Else Begin

        Send Stop_Box ("The file ' + sFile + "' was NOT deleted successfully" "Error!")

    End

End_Procedure

 

Send DeleteMyNotes

 

Notes

EraseFile "C:\Temp\Test"

EraseFile "C:\Temp\Test\*.*"