LATEST UPDATES
ShareHolder Finder v0.9.3 is now released!!! Check Product Page for more details.
✉ info@automationdevelopers.com

ITS ALL ABOUT AUTOMATION

Saturday, 16 April 2016

AutoIt - Delete file


Author Post Date Saturday, 16 April 2016
To delete one or more files, the function FileDelete ( "filename" ) is used.

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

If the "path" passed to FileDelete() is a folder, the files therein will be deleted just as if we use the *.* wildcard mask.

The function returns 1 for success and 0 for failure (if files are not deleted or do not exist).

Example:

#include <MsgBoxConstants.au3>
#include <FileConstants.au3>

;Assign the file path to a variable.
Local $sFilePath = @ScriptDir & "\temp.txt"

;Create temp.txt.
If Not FileWrite($sFilePath, "This is an example of using FileRename.") Then
    MsgBox($MB_SYSTEMMODAL, "", "An error occurred while writing the file.")
EndIf

;Execute the delete function.
Local $iDelete = FileDelete($sFilePath)

;Display the status after checking the returned value.
If $iDelete Then
    MsgBox($MB_SYSTEMMODAL, "", "The file was successfuly deleted.")
Else
    MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst deleting the file.")
EndIf

Related Posts




Interesting? Share and Let Others Know.

Post a Comment