Function Reference


Delete one or more files.

FileDelete ( "filename" )


Filename The path of the file(s) to delete. (* and ? wildcards accepted - See Remarks)

Return Value

Success: 1.
Failure: 0 if files are not deleted or do not exist.


See FileFindFirstFile() for a discussion about wildcards.

Note: If the "path" passed to FileDelete() is a folder, the files therein will be deleted just as if you had used the *.* mask.

Some file attributes can make the deletion impossible, if this is the case look at FileSetAttrib() to change the attributes of a file.


DirRemove, FileCopy, FileMove, FileRecycle, FileRecycleEmpty


#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>


Func Example()
    ; Create a constant variable in Local scope of the filepath that will be read/written to.
    Local Const $sFilePath = _WinAPI_GetTempFileName(@TempDir)

    ; Create a temporary file to read data from.
    If Not FileWrite($sFilePath, "This is an example of using FileDelete.") Then
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.")
        Return False

    ; Display the contents of the file passing the filepath to FileRead instead of a handle returned by FileOpen.
    MsgBox($MB_SYSTEMMODAL, "", "Contents of the file:" & @CRLF & FileRead($sFilePath))

    ; Delete the temporary file.
    Local $iDelete = FileDelete($sFilePath)

    ; Display a message of whether the file was deleted.
    If $iDelete Then
        MsgBox($MB_SYSTEMMODAL, "", "The file was successfuly deleted.")
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst deleting the file.")
EndFunc   ;==>Example