函数参考


DirRemove

删除一个目录/文件夹.

DirRemove ( "路径" [, 递归遍历] )

参数

路径 要删除的文件夹的路径.
递归遍历 [可选参数] 此标志参数用以决定是否删除子目录.
  0 = (默认)不删除文件及子目录
  1 = 删除文件及子目录(类似于 DOS 下的 DelTree 命令)

返回值

成功: 返回值为1.
失败: 返回值为0,说明在删除目录的过程中遇到错误(或者指定目录并不存在).

注意/说明

一些目录属性会导致无法移除.

相关

DirCreate, DirCopy, DirMove, FileDelete, FileRecycle

示例/演示


; Delete C:\Test1 and all subdirs and files
Local $sFldr1 = "C:\Test1\"
Local $sFldr2 = "C:\Test1\Folder1\"
Local $sFldr3 = "C:\Test1\Folder1\Folder2\"
If DirGetSize($sFldr1) = -1 Then
    DirCreate($sFldr3)
    Local $explorer = RunWait("explorer /root, C:\Test1\Folder1")
    Local $handle = WinGetHandle($explorer)
    MsgBox(262144, "Message", "Explorer is opened with Folder2 displayed.")
    DirRemove($sFldr3, 1)
    MsgBox(262144, "Message", "The sub folder: Folder2 has been deleted.")
    WinClose($handle)
    DirRemove($sFldr1, 1) ;clean up test folders
Else
    MsgBox(48, $sFldr1, "Directory already exists!")
EndIf