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
#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
- AutoIt - Check if a file exists
- AutoIt - Copy file
- AutoIt - Move file
- AutoIt - Rename a file
- AutoIt - Check if a file or folder is Read Only
- AutoIt - Set a file or folder as Read Write
Interesting? Share and Let Others Know.
Post a Comment