Location My.Computer.FileSystem.DeleteDirectory Syntax My.Computer.FileSystem.DeleteDirectory(path, onDirectoryNotEmpty) or: My.Computer.FileSystem.DeleteDirectory(path, showUI, _ recycle[, onUserCancel])
path (required; String) The path to the directory to be deleted.
onDirectoryNotEmpty (required in syntax 1; DeleteDirectoryOption enumeration) Indicates the action to take if the directory is not empty. One of the following Microsoft.VisualBasic.FileIO.DeleteDirectoryOption enumeration values. Value | Description |
---|
DeleteAllContents | Deletes all subordinate items. | ThrowIfDirectoryNonEmpty | Throws an exception. The Data property of the Exception object lists the blocking items. |
If this parameter is missing, DeleteAllContents is used by default.
showUI (optional; UIOption enumeration) Indicates whether error or progress dialog windows should appear during the delete. One of the following Microsoft.VisualBasic.FileIO.UIOption enumeration values. Value | Description |
---|
OnlyErrorDialogs | Only shows error dialog boxes; does not display progress | AllDialogs | Shows progress and error dialogs |
If this parameter is missing, OnlyErrorDialogs is used by default.
recycle (optional; RecycleOption enumeration) Indicates the state of the directory after it has been deleted. One of the following Microsoft.VisualBasic.FileIO.RecycleOption enumeration values. Value | Description |
---|
DeletePermanently | Permanently deletes the directory and its contents | SendToRecycleBin | Moves the directory to the Recycle Bin |
If this parameter is missing, DeletePermanently is used by default.
onUserCancel (optional; UICancelOption enumeration) The progress window includes a Cancel button. When pressed, the method takes action based on this parameter. One of the following Microsoft.VisualBasic.FileIO.UICancelOption enumeration values. Value | Description |
---|
DoNothing | Aborts the deletion but returns no information indicating that the deletion was cancelled | ThrowException | Throws an exception |
If this parameter is missing, ThrowException is used by default. Description The DeleteDirectory method deletes the indicated directory and all of its contents. Usage at a Glance Visual Basic includes an RmDir procedure that also deletes directories. However, that procedure fails if the directory is not empty. An exception is thrown if the path parameter is missing, invalid, or refers to a file. An exception is thrown if the directory does not exist or is in use (including any of its contents). An exception is thrown if the user lacks sufficient file access permissions. Example The following example permanently deletes a directory and its contents. My.Computer.FileSystem.DeleteDirectory( _ ("C:\OldFiles", DeleteAllContents) Related Framework Entries Microsoft.VisualBasic.FileIO.FileSystem.DeleteDirectory Method Microsoft.VisualBasic.MyServices.FileSystemProxy.DeleteDirectory Method System.IO.Directory.Delete Method See Also CopyDirectory Method, CopyFile Method, CreateDirectory Method, DeleteFile Method, FileSystem Object, MoveDirectory Method, MoveFile Method, RenameDirectory Method, RenameFile Method |