DeleteDirectory

Deletes a directory.


Syntax

FileSystem.DeleteDirectory(Directory, DeleteDirectoryOption)

FileSystem.DeleteDirectory(Directory, UIOption, RecycleOption)

FileSystem.DeleteDirectory(Directory, UIOption, RecycleOption, UICancelOption)


Parameters


Directory

String, input



Directory to be deleted.


DeleteDirectoryOption

Enumeration, input



Specifies what should be done when a directory that is to be deleted contains files or directories. Default is DeleteAllContents.


UIOption

Enumeration, input



Whether to visually track the operation's progress. Default is OnlyErrorDialogs.


RecycleOption

Enumeration, input



Specifies whether the directory and it's contents should be deleted permanently or placed in the Recycle Bin. Default is DeletePermanently.


UICancelOption

Enumeration, input



Specifies what should be done if the user clicks Cancel during the operation. Default is ThrowException.


Remarks


DeleteDirectoryOption



DeleteDirectoryOption.DeleteAllContents

Delete the contents of the directory along with the directory. Default.


DeleteDirectoryOption.ThrowIfDirectoryNonEmpty

Throw an IOException if the directory is not empty. The Data property of the exception lists the file(s) that could not be deleted.


UIOption



UIOption.AllDialogs

Show progress dialog box and any error dialog boxes.


UIOption.OnlyErrorDialogs

Only show error dialog boxes and hide progress dialog boxes. Default.


UICancelOption



UICancelOption.DoNothing

Do nothing when the user clicks Cancel.


UICancelOption.ThrowException

Throw an exception when the user clicks Cancel. Default.


RecycleOption



RecycleOption.DeletePermanently

Delete the directory permanently. Default.


RecycleOption.SendToRecycleBin

Send the directory to the Recycle Bin.


Examples


This example deletes the specified directory only if it is empty:


Sub Main()

FileSystem.DeleteDirectory "C:\Users\Public\My Directory\", DeleteDirectoryOption.ThrowIfDirectoryNonEmpty

End Sub


This example deletes the specified directory and all of its contents:


Sub Main()

FileSystem.DeleteDirectory "C:\Users\Public\My Directory\", DeleteDirectoryOption.DeleteAllContents

End Sub


This example deletes the specified directory and all of its contents, asking the user to confirm the deletion, but does not send the contents to the Recycle Bin:


Sub Main()

FileSystem.DeleteDirectory "C:\Users\Public\My Directory\", UIOption.AllDialogs, RecycleOption.DeletePermanently, UICancelOption.ThrowException

End Sub


This example deletes the specified directory and all of its contents, sending them to the Recycle Bin, but does not show the progress of the operation:


Sub Main()

FileSystem.DeleteDirectory "C:\Users\Public\My Directory\", UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin, UICancelOption.ThrowException

End Sub