See Also: File I/O Commands, CopyFile, File_Exist, Remove_Directory, Set_Directory
Deletes one or more disk files
EraseFile {file-spec}
Where
{file-spec} is the specification of a file or set of files (including wildcard characters), optionally including a path.
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.
The sample deletes the file "hello.txt" in the current working folder (since a path is not specified).
EraseFile "hello.txt"
The sample deletes all files with the file extension "txt" in the "C:\My Notes" folder.
EraseFile "C:\My Notes\*.txt"
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
EraseFile deletes files specified in {file-spec} without triggering any error, warning or notification.
If EraseFile is executed on a non existent file, no error will be triggered. Use the File_Exist command to determine whether a file exists before erasing the file(s).
You may use "wild card" (ambiguous) file names for {file-spec}. Be extremely careful when using wildcards in EraseFile command statements. EraseFile provides no verification or protections unless you program them, and erroneous usage could potentially erase important data!
Specifying a folder name in {file-spec} with no file name(s) specified will erase all files in that folder.
For example, the following 2 lines of code are functionally equivalent and result in the deletion of all files in the "C:\Temp\Test" folder:
EraseFile "C:\Temp\Test"
EraseFile "C:\Temp\Test\*.*"
EraseFile may behave differently on different operating systems. For example, EraseFile "" will delete all files in the current folder on some versions of Windows, but no files on other versions. Thorough testing in all deployed environments is advised.
If you want to erase all data from a database table but leave its structure intact, you can use the Zerofile command.