# Function Reference

# DirRemove

Deletes a directory/folder.

DirRemove ( "path" [, recurse = 0] )

## Parameters

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".

## Return Value

Success: | 1.
Failure: | 0 if there is an error removing the directory (or if directory does not exist).

## Remarks

Some directory attributes can make the deletion impossible, therefore if this is the case look at FileSetAttrib() to change the attributes of a directory.

## Related

DirCopy, DirCreate, DirMove, FileDelete, FileRecycle

## Example

    #include <AutoItConstants.au3>
    #include <MsgBoxConstants.au3>

    Example()

    Func Example()
        ; Create a constant variable in Local scope of the directory.
        Local Const $sFilePath = @TempDir & "\DirRemoveFolder"

        ; If the directory exists the don't continue.
        If FileExists($sFilePath) Then
            MsgBox($MB_SYSTEMMODAL, "", "An error occurred. The directory already exists.")
            Return False
        EndIf

        ; Open the temporary directory.
        ShellExecute(@TempDir)

        ; Create the directory.
        DirCreate($sFilePath)

        ; Display a message of the directory creation.
        MsgBox($MB_SYSTEMMODAL, "", "The directory has been created.")

        ; Remove the directory and all sub-directories.
        DirRemove($sFilePath, $DIR_REMOVE)

        ; Display a message of the directory removal.
        MsgBox($MB_SYSTEMMODAL, "", "The sub folder: Folder2 has been deleted.")
    EndFunc   ;==>Example