FileSystem.DeleteDirectory FileSystem.DeleteDirectory FileSystem.DeleteDirectory FileSystem.DeleteDirectory Method

Definition

Deletes a directory.

Overloads

DeleteDirectory(String, UIOption, RecycleOption, UICancelOption) DeleteDirectory(String, UIOption, RecycleOption, UICancelOption) DeleteDirectory(String, UIOption, RecycleOption, UICancelOption) DeleteDirectory(String, UIOption, RecycleOption, UICancelOption)

Deletes a directory.

DeleteDirectory(String, UIOption, RecycleOption) DeleteDirectory(String, UIOption, RecycleOption) DeleteDirectory(String, UIOption, RecycleOption) DeleteDirectory(String, UIOption, RecycleOption)

Deletes a directory.

DeleteDirectory(String, DeleteDirectoryOption) DeleteDirectory(String, DeleteDirectoryOption) DeleteDirectory(String, DeleteDirectoryOption) DeleteDirectory(String, DeleteDirectoryOption)

Deletes a directory.

DeleteDirectory(String, UIOption, RecycleOption, UICancelOption) DeleteDirectory(String, UIOption, RecycleOption, UICancelOption) DeleteDirectory(String, UIOption, RecycleOption, UICancelOption) DeleteDirectory(String, UIOption, RecycleOption, UICancelOption)

Deletes a directory.

public:
 static void DeleteDirectory(System::String ^ directory, Microsoft::VisualBasic::FileIO::UIOption showUI, Microsoft::VisualBasic::FileIO::RecycleOption recycle, Microsoft::VisualBasic::FileIO::UICancelOption onUserCancel);
public static void DeleteDirectory (string directory, Microsoft.VisualBasic.FileIO.UIOption showUI, Microsoft.VisualBasic.FileIO.RecycleOption recycle, Microsoft.VisualBasic.FileIO.UICancelOption onUserCancel);
static member DeleteDirectory : string * Microsoft.VisualBasic.FileIO.UIOption * Microsoft.VisualBasic.FileIO.RecycleOption * Microsoft.VisualBasic.FileIO.UICancelOption -> unit
Public Shared Sub DeleteDirectory (directory As String, showUI As UIOption, recycle As RecycleOption, onUserCancel As UICancelOption)

Parameters

directory
String String String String

Directory to be deleted.

showUI
UIOption UIOption UIOption UIOption

Specifies whether to visually track the operation's progress. Default is UIOption.OnlyErrorDialogs.

recycle
RecycleOption RecycleOption RecycleOption RecycleOption

Specifies whether or not the deleted file should be sent to the Recycle Bin. Default is RecycleOption.DeletePermanently.

onUserCancel
UICancelOption UICancelOption UICancelOption UICancelOption

Specifies whether to throw an exception if the user clicks Cancel.

Exceptions

The path is a zero-length string, is malformed, contains only white space, or contains invalid characters (including wildcard characters). The path is a device path (starts with \\.\).

A file in the directory or subdirectory is in use.

The path exceeds the system-defined maximum length.

The user does not have required permissions.

The user cancels the operation or the directory cannot be deleted.

Examples

The example deletes the directory OldDirectory only if it is empty.

My.Computer.FileSystem.DeleteDirectory(
  "C:\OldDirectory",
  FileIO.DeleteDirectoryOption.ThrowIfDirectoryNonEmpty)

This example deletes the directory OldDirectory and all of its contents.

My.Computer.FileSystem.DeleteDirectory(
  "C:\OldDirectory",
  FileIO.DeleteDirectoryOption.DeleteAllContents)

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

My.Computer.FileSystem.DeleteDirectory(
  "C:\OldDirectory",
  FileIO.UIOption.AllDialogs,
  FileIO.RecycleOption.DeletePermanently,
  FileIO.UICancelOption.ThrowException)

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

My.Computer.FileSystem.DeleteDirectory(
 "C:\OldDirectory",
 FileIO.UIOption.AllDialogs,
 FileIO.RecycleOption.SendToRecycleBin,
 FileIO.UICancelOption.ThrowException)

Remarks

The showUI, recycle, and onUserCancel parameters are not supported in applications that are not user interactive, such as Windows Services.

Security

FileIOPermission
Controls the ability to access files and folders. Associated enumeration: Unrestricted.

UIPermission
Controls the permissions related to user interfaces and the clipboard. Associated enumeration: SafeSubWindows.

See also

DeleteDirectory(String, UIOption, RecycleOption) DeleteDirectory(String, UIOption, RecycleOption) DeleteDirectory(String, UIOption, RecycleOption) DeleteDirectory(String, UIOption, RecycleOption)

Deletes a directory.

public:
 static void DeleteDirectory(System::String ^ directory, Microsoft::VisualBasic::FileIO::UIOption showUI, Microsoft::VisualBasic::FileIO::RecycleOption recycle);
public static void DeleteDirectory (string directory, Microsoft.VisualBasic.FileIO.UIOption showUI, Microsoft.VisualBasic.FileIO.RecycleOption recycle);
static member DeleteDirectory : string * Microsoft.VisualBasic.FileIO.UIOption * Microsoft.VisualBasic.FileIO.RecycleOption -> unit
Public Shared Sub DeleteDirectory (directory As String, showUI As UIOption, recycle As RecycleOption)

Parameters

directory
String String String String

Directory to be deleted.

showUI
UIOption UIOption UIOption UIOption

Specifies whether to visually track the operation's progress. Default is UIOption.OnlyErrorDialogs.

recycle
RecycleOption RecycleOption RecycleOption RecycleOption

Specifies whether or not the deleted file should be sent to the Recycle Bin. Default is RecycleOption.DeletePermanently.

Exceptions

The path is a zero-length string, is malformed, contains only white space, or contains invalid characters (including wildcard characters). The path is a device path (starts with \\.\).

A file in the directory or subdirectory is in use.

The path exceeds the system-defined maximum length.

The user does not have required permissions.

The user cancels the operation or the directory cannot be deleted.

Examples

The example deletes the directory OldDirectory only if it is empty.

My.Computer.FileSystem.DeleteDirectory(
  "C:\OldDirectory",
  FileIO.DeleteDirectoryOption.ThrowIfDirectoryNonEmpty)

This example deletes the directory OldDirectory and all of its contents.

My.Computer.FileSystem.DeleteDirectory(
  "C:\OldDirectory",
  FileIO.DeleteDirectoryOption.DeleteAllContents)

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

My.Computer.FileSystem.DeleteDirectory(
  "C:\OldDirectory",
  FileIO.UIOption.AllDialogs,
  FileIO.RecycleOption.DeletePermanently,
  FileIO.UICancelOption.ThrowException)

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

My.Computer.FileSystem.DeleteDirectory(
 "C:\OldDirectory",
 FileIO.UIOption.AllDialogs,
 FileIO.RecycleOption.SendToRecycleBin,
 FileIO.UICancelOption.ThrowException)

Remarks

The showUI and recycle parameters are not supported in applications that are not user interactive, such as Windows Services.

Security

FileIOPermission
Controls the ability to access files and folders. Associated enumeration: Unrestricted.

UIPermission
Controls the permissions related to user interfaces and the clipboard. Associated enumeration: SafeSubWindows.

See also

DeleteDirectory(String, DeleteDirectoryOption) DeleteDirectory(String, DeleteDirectoryOption) DeleteDirectory(String, DeleteDirectoryOption) DeleteDirectory(String, DeleteDirectoryOption)

Deletes a directory.

public:
 static void DeleteDirectory(System::String ^ directory, Microsoft::VisualBasic::FileIO::DeleteDirectoryOption onDirectoryNotEmpty);
public static void DeleteDirectory (string directory, Microsoft.VisualBasic.FileIO.DeleteDirectoryOption onDirectoryNotEmpty);
static member DeleteDirectory : string * Microsoft.VisualBasic.FileIO.DeleteDirectoryOption -> unit
Public Shared Sub DeleteDirectory (directory As String, onDirectoryNotEmpty As DeleteDirectoryOption)

Parameters

directory
String String String String

Directory to be deleted.

onDirectoryNotEmpty
DeleteDirectoryOption DeleteDirectoryOption DeleteDirectoryOption DeleteDirectoryOption

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

Exceptions

The path is a zero-length string, is malformed, contains only white space, or contains invalid characters (including wildcard characters). The path is a device path (starts with \\.\).

A file in the directory or subdirectory is in use.

The path exceeds the system-defined maximum length.

The user does not have required permissions.

The user cancels the operation or the directory cannot be deleted.

Examples

The example deletes the directory OldDirectory only if it is empty.

My.Computer.FileSystem.DeleteDirectory(
  "C:\OldDirectory",
  FileIO.DeleteDirectoryOption.ThrowIfDirectoryNonEmpty)

This example deletes the directory OldDirectory and all of its contents.

My.Computer.FileSystem.DeleteDirectory(
  "C:\OldDirectory",
  FileIO.DeleteDirectoryOption.DeleteAllContents)

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

My.Computer.FileSystem.DeleteDirectory(
  "C:\OldDirectory",
  FileIO.UIOption.AllDialogs,
  FileIO.RecycleOption.DeletePermanently,
  FileIO.UICancelOption.ThrowException)

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

My.Computer.FileSystem.DeleteDirectory(
 "C:\OldDirectory",
 FileIO.UIOption.AllDialogs,
 FileIO.RecycleOption.SendToRecycleBin,
 FileIO.UICancelOption.ThrowException)

Security

FileIOPermission
Controls the ability to access files and folders. Associated enumeration: Unrestricted.

See also

Applies to