Function Reference


FileDelete

Delete one or more files.

FileDelete ( "filename" )

Parameters

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.

Remarks

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.

Related

DirRemove(), FileCopy(), FileMove(), FileRecycle(), FileRecycleEmpty()

Example

#include <MsgBoxConstants.au3>

Example()

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

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

    ; 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.")
    Else
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst deleting the file.")
    EndIf
EndFunc   ;==>Example

; Create a file.
Func FileCreate($sFilePath, $sString)
    Local $bReturn = True ; Create a variable to store a boolean value.
    If FileExists($sFilePath) = 0 Then $bReturn = FileWrite($sFilePath, $sString) = 1 ; If FileWrite returned 1 this will be True otherwise False.
    Return $bReturn ; Return the boolean value of either True of False, depending on the return value of FileWrite.
EndFunc   ;==>FileCreate