FileSystemProxy.DeleteDirectory 方法

定义

删除目录。Deletes a directory.

重载

DeleteDirectory(String, UIOption, RecycleOption)

删除目录。Deletes a directory.

DeleteDirectory(String, UIOption, RecycleOption, UICancelOption)

删除目录。Deletes a directory.

DeleteDirectory(String, DeleteDirectoryOption)

删除目录。Deletes a directory.

DeleteDirectory(String, UIOption, RecycleOption)

删除目录。Deletes a directory.

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

参数

directory
String

要删除的目录。Directory to be deleted.

showUI
UIOption

指定是否对操作进度进行可视跟踪。Specifies whether to visually track the operation's progress. 默认值为 UIOption.OnlyErrorDialogsDefault is UIOption.OnlyErrorDialogs.

recycle
RecycleOption

指定是否应将删除的文件发送到“回收站”。Specifies whether or not the deleted file should be sent to the Recycle Bin. 默认值为 RecycleOption.DeletePermanentlyDefault is RecycleOption.DeletePermanently.

异常

路径是零长度字符串、格式不正确、仅包含空白,或者包含无效字符(包括通配符)。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 \\.\).

directoryNothing 或空字符串。directory is Nothing or an empty string.

目录不存在,或者目录是一个文件。The directory does not exist or is a file.

目录或子目录中的某个文件正被使用。A file in the directory or subdirectory is in use.

目录名中包含冒号 (:)。The directory name contains a colon (:).

路径超过了系统定义的最大长度。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.

示例

仅当目录为空时,此示例才会删除目录 OldDirectoryThe example deletes the directory OldDirectory only if it is empty.

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

此示例将删除目录 OldDirectory 及其所有内容。This example deletes the directory OldDirectory and all of its contents.

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

此示例将删除目录 OldDirectory 及其所有内容,要求用户确认删除,但不会将内容发送到回收站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)

此示例将删除目录 OldDirectory 及其所有内容,并将其发送到回收站,但不会显示操作的进度。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)

注解

不是用户交互的应用程序(如 Windows 服务)不支持 showUIrecycle 参数。The showUI and recycle parameters are not supported in applications that are not user interactive, such as Windows Services.

安全性

FileIOPermission
控制文件和文件夹的访问权限。Controls the ability to access files and folders. 关联枚举:UnrestrictedAssociated enumeration: Unrestricted.

UIPermission
控制与用户界面和剪贴板相关的权限。Controls the permissions related to user interfaces and the clipboard. 关联枚举:SafeSubWindowsAssociated enumeration: SafeSubWindows.

另请参阅

DeleteDirectory(String, UIOption, RecycleOption, UICancelOption)

删除目录。Deletes a directory.

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

参数

directory
String

要删除的目录。Directory to be deleted.

showUI
UIOption

指定是否对操作进度进行可视跟踪。Specifies whether to visually track the operation's progress. 默认值为 UIOption.OnlyErrorDialogsDefault is UIOption.OnlyErrorDialogs.

recycle
RecycleOption

指定是否应将删除的文件发送到“回收站”。Specifies whether or not the deleted file should be sent to the Recycle Bin. 默认值为 RecycleOption.DeletePermanentlyDefault is RecycleOption.DeletePermanently.

onUserCancel
UICancelOption

指定在用户单击“取消”时是否引发异常。Specifies whether to throw an exception if the user clicks Cancel.

异常

路径是零长度字符串、格式不正确、仅包含空白,或者包含无效字符(包括通配符)。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 \\.\).

directoryNothing 或空字符串。directory is Nothing or an empty string.

目录不存在,或者目录是一个文件。The directory does not exist or is a file.

目录或子目录中的某个文件正被使用。A file in the directory or subdirectory is in use.

目录名中包含冒号 (:)。The directory name contains a colon (:).

路径超过了系统定义的最大长度。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.

示例

仅当目录为空时,此示例才会删除目录 OldDirectoryThe example deletes the directory OldDirectory only if it is empty.

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

此示例将删除目录 OldDirectory 及其所有内容。This example deletes the directory OldDirectory and all of its contents.

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

此示例将删除目录 OldDirectory 及其所有内容,要求用户确认删除,但不会将内容发送到回收站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)

此示例将删除目录 OldDirectory 及其所有内容,并将其发送到回收站,但不会显示操作的进度。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)

注解

不是用户交互的应用程序(如 Windows 服务)不支持 showUIrecycleonUserCancel 参数。The showUI, recycle, and onUserCancel parameters are not supported in applications that are not user interactive, such as Windows Services.

安全性

FileIOPermission
控制文件和文件夹的访问权限。Controls the ability to access files and folders. 关联枚举:UnrestrictedAssociated enumeration: Unrestricted.

UIPermission
控制与用户界面和剪贴板相关的权限。Controls the permissions related to user interfaces and the clipboard. 关联枚举:SafeSubWindowsAssociated enumeration: SafeSubWindows.

另请参阅

DeleteDirectory(String, DeleteDirectoryOption)

删除目录。Deletes a directory.

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

参数

directory
String

要删除的目录。Directory to be deleted.

onDirectoryNotEmpty
DeleteDirectoryOption

指定当要删除的目录中含有文件或目录时应采取的操作。Specifies what should be done when a directory that is to be deleted contains files or directories. 默认值为 DeleteDirectoryOption.DeleteAllContentsDefault is DeleteDirectoryOption.DeleteAllContents.

异常

路径是零长度字符串、格式不正确、仅包含空白,或者包含无效字符(包括通配符)。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 \\.\).

directoryNothing 或空字符串。directory is Nothing or an empty string.

目录不存在,或者目录是一个文件。The directory does not exist or is a file.

目录或子目录中的某个文件正被使用。A file in the directory or subdirectory is in use.

目录名中包含冒号 (:)。The directory name contains a colon (:).

路径超过了系统定义的最大长度。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.

示例

仅当目录为空时,此示例才会删除目录 OldDirectoryThe example deletes the directory OldDirectory only if it is empty.

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

此示例将删除目录 OldDirectory 及其所有内容。This example deletes the directory OldDirectory and all of its contents.

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

此示例将删除目录 OldDirectory 及其所有内容,要求用户确认删除,但不会将内容发送到回收站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)

此示例将删除目录 OldDirectory 及其所有内容,并将其发送到回收站,但不会显示操作的进度。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)

安全性

FileIOPermission
控制文件和文件夹的访问权限。Controls the ability to access files and folders. 关联枚举:UnrestrictedAssociated enumeration: Unrestricted.

另请参阅

适用于