DirRemove
删除目录/文件夹.
DirRemove ( "path" [, recurse = 0] )
参数
path
|
目标目录路径
|
recurse
|
[可选] 确定是否删除子目录.
$DIR_DEFAULT (0) = (默认) 如文件夹为空, 则删除
$DIR_REMOVE (1) = 删除文件及子目录(类似 DOS 的 DelTree 命令)
常量定义在 "AutoItConstants.au3"
|
返回值
成功:
|
返回 1.
|
失败:
|
返回 0, 删除目录发生错误(或目录不存在).
|
备注
某些目录属性会导致无法移除. 因此需使用 FileSetAttrib() 事先更改目录的属性.
函数示例
#include <MsgBoxConstants.au3>
; Delete C:\Test1 and all subdirs and files
Example()
Func Example()
Local $sFldr1 = "C:\Test1\"
Local $sFldr2 = "C:\Test1\Folder1\"
Local $sFldr3 = "C:\Test1\Folder1\Folder2\"
If DirGetSize($sFldr1) <> -1 Then
MsgBox($MB_SYSTEMMODAL, "", "Directory already exists!")
Return False
EndIf
DirCreate($sFldr3)
RunWait("explorer /root, C:\Test1\Folder1")
Local $hWnd = WinGetHandle("[TITLE:Folder1;CLASS:CabinetWClass]")
MsgBox($MB_SYSTEMMODAL, "", "Explorer is opened with Folder2 displayed.")
DirRemove($sFldr3, 1)
MsgBox($MB_SYSTEMMODAL, "", "The sub folder: Folder2 has been deleted.")
WinClose($hWnd)
DirRemove($sFldr2) ;clean up test folders
DirRemove($sFldr1) ;clean up test folders
EndFunc ;==>Example
----------------------------------------
该函数可以通过命令 exect 调用
参见:
DirCreate, DirCopy, DirMove, FileDelete, FileRecycle
exect=DirRemove('C:\Backups\MyDocs',1) ;; 删除MyDocs文件夹
© Аверин Андрей для Total Commander Image Averin-And@yandex.ru
|