Deletes a directory/folder.
DirRemove ( "path" [, recurse = 0] )
|path||Path of the directory to remove.|
|recurse||[optional] Use this flag to specify if you want to delete sub-directories too.
$DIR_DEFAULT (0) = (default) deletes the folder, only if it is empty
$DIR_REMOVE (1) = remove files and subdirectories (like the DOS DelTree command)
Constants are define in "AutoItConstants.au3".
|Failure:||0 if there is an error removing the directory (or if directory does not exist).|
Some directory attributes can make the deletion impossible, therefore if this is the case look at FileSetAttrib() to change the attributes of a directory.
DirCopy, DirCreate, DirMove, FileDelete, FileRecycle
#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