FileDelete
删除一或多个文件.
FileDelete ( "filename" )
参数
Filename
|
被删除文件的路径. 可使用通配符 * 和 ?. 见备注
|
返回值
成功:
|
返回 1.
|
失败:
|
返回 0, 文件无法删除或不存在.
|
备注
通配符约定见 FileFindFirstFile.
注意: 如果 "路径" 参数为一个文件夹, 则删除文件夹及其所有文件. 等同于使用 *.* 通配符.
某些文件属性将不允许删除操作, 此时应先调用 FileSetAttrib() 函数, 修改文件属性.
函数示例
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
Example()
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
EndIf
; 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
----------------------------------------
该函数可以通过命令 exect 调用
参见:
FileCopy, FileMove, FileRecycle, DirRemove, FileRecycleEmpty
exect=FileDelete('D:\*.tmp') ;; 从磁盘根目录中删除扩展名为.tmp的所有文件D:\
exect=FileDelete('C:\Test\test.txt') ;; 删除文件test.txt
© Аверин Андрей для Total Commander Image Averin-And@yandex.ru
|