FileSystem.MoveDirectory 方法

定义

将目录从一个位置移动到另一个位置。Moves a directory from one location to another.

重载

MoveDirectory(String, String)

将目录从一个位置移动到另一个位置。Moves a directory from one location to another.

MoveDirectory(String, String, UIOption)

将目录从一个位置移动到另一个位置。Moves a directory from one location to another.

MoveDirectory(String, String, Boolean)

将目录从一个位置移动到另一个位置。Moves a directory from one location to another.

MoveDirectory(String, String, UIOption, UICancelOption)

将目录从一个位置移动到另一个位置。Moves a directory from one location to another.

MoveDirectory(String, String)

将目录从一个位置移动到另一个位置。Moves a directory from one location to another.

public:
 static void MoveDirectory(System::String ^ sourceDirectoryName, System::String ^ destinationDirectoryName);
public static void MoveDirectory (string sourceDirectoryName, string destinationDirectoryName);
static member MoveDirectory : string * string -> unit
Public Shared Sub MoveDirectory (sourceDirectoryName As String, destinationDirectoryName As String)

参数

sourceDirectoryName
String

要移动的目录的路径。Path of the directory to be moved.

destinationDirectoryName
String

源目录将移到的目录的路径。Path of the directory to which the source directory is being moved.

例外

路径由于以下原因之一无效:是零长度字符串;仅为空白;包含无效字符;是一个设备路径(以 \\.\ 开头)。The path is not valid for one of the following reasons: it is a zero-length string; it contains only white space; it contains invalid characters; or it is a device path (starts with \\.\).

sourceDirectoryNamedestinationDirectoryNameNothing 或空字符串。sourceDirectoryName or destinationDirectoryName is Nothing or an empty string.

该目录不存在。The directory does not exist.

源是根目录,或者,源路径与目标路径相同。The source is a root directory or The source path and the target path are the same.

路径超过了系统定义的最大长度。The path exceeds the system-defined maximum length.

操作为循环。The operation is cyclic.

路径中的文件名或目录名包含冒号 (:),或格式无效。A file or directory name in the path contains a colon (:) or is in an invalid format.

该用户缺少查看该路径所必需的权限。The user lacks necessary permissions to view the path.

该用户没有必需的权限。The user does not have required permission.

示例

此示例将 Directory1 移动 Directory2内。This example moves Directory1 inside Directory2.

My.Computer.FileSystem.MoveDirectory("C:\Directory1", "C:\Directory2")

此示例在 Directory2内移动 Directory1,并覆盖目录(如果已存在)。This example moves Directory1 inside Directory2, overwriting the directory if it already exists.

My.Computer.FileSystem.MoveDirectory("C:\Directory1", "C:\Directory2",
True)

注解

如果尝试将目录移动到不存在的目录中,则将创建目标结构。If an attempt is made to move a directory inside a directory that does not exist, the target structure will be created.

另请参阅

MoveDirectory(String, String, UIOption)

将目录从一个位置移动到另一个位置。Moves a directory from one location to another.

public:
 static void MoveDirectory(System::String ^ sourceDirectoryName, System::String ^ destinationDirectoryName, Microsoft::VisualBasic::FileIO::UIOption showUI);
public static void MoveDirectory (string sourceDirectoryName, string destinationDirectoryName, Microsoft.VisualBasic.FileIO.UIOption showUI);
static member MoveDirectory : string * string * Microsoft.VisualBasic.FileIO.UIOption -> unit
Public Shared Sub MoveDirectory (sourceDirectoryName As String, destinationDirectoryName As String, showUI As UIOption)

参数

sourceDirectoryName
String

要移动的目录的路径。Path of the directory to be moved.

destinationDirectoryName
String

源目录将移到的目录的路径。Path of the directory to which the source directory is being moved.

showUI
UIOption

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

例外

路径由于以下原因之一无效:是零长度字符串;仅为空白;包含无效字符;是一个设备路径(以 \\.\ 开头)。The path is not valid for one of the following reasons: it is a zero-length string; it contains only white space; it contains invalid characters; or it is a device path (starts with \\.\).

sourceDirectoryNamedestinationDirectoryNameNothing 或空字符串。sourceDirectoryName or destinationDirectoryName is Nothing or an empty string.

该目录不存在。The directory does not exist.

目标目录已存在,并且 overwrite 设置为 FalseThe target directory already exists and overwrite is set to False.

路径超过了系统定义的最大长度。The path exceeds the system-defined maximum length.

操作为循环。The operation is cyclic.

路径中的文件名或目录名包含冒号 (:),或格式无效。A file or directory name in the path contains a colon (:) or is in an invalid format.

该用户缺少查看该路径所必需的权限。The user lacks necessary permissions to view the path.

该用户没有必需的权限。The user does not have required permission.

示例

此示例将 Directory1 移动 Directory2内。This example moves Directory1 inside Directory2.

My.Computer.FileSystem.MoveDirectory("C:\Directory1", "C:\Directory2")

此示例在 Directory2内移动 Directory1,并覆盖目录(如果已存在)。This example moves Directory1 inside Directory2, overwriting the directory if it already exists.

My.Computer.FileSystem.MoveDirectory("C:\Directory1", "C:\Directory2",
True)

注解

如果尝试将目录移动到不存在的目录中,则将创建目标结构。If an attempt is made to move a directory inside a directory that does not exist, the target structure will be created.

另请参阅

MoveDirectory(String, String, Boolean)

将目录从一个位置移动到另一个位置。Moves a directory from one location to another.

public:
 static void MoveDirectory(System::String ^ sourceDirectoryName, System::String ^ destinationDirectoryName, bool overwrite);
public static void MoveDirectory (string sourceDirectoryName, string destinationDirectoryName, bool overwrite);
static member MoveDirectory : string * string * bool -> unit
Public Shared Sub MoveDirectory (sourceDirectoryName As String, destinationDirectoryName As String, overwrite As Boolean)

参数

sourceDirectoryName
String

要移动的目录的路径。Path of the directory to be moved.

destinationDirectoryName
String

源目录将移到的目录的路径。Path of the directory to which the source directory is being moved.

overwrite
Boolean

如果应覆盖现有目录,则为 True;否则为 FalseTrue if existing directories should be overwritten; otherwise False. 默认值为 FalseDefault is False.

例外

路径由于以下原因之一无效:是零长度字符串;仅为空白;包含无效字符;是一个设备路径(以 \\.\ 开头)。The path is not valid for one of the following reasons: it is a zero-length string; it contains only white space; it contains invalid characters; or it is a device path (starts with \\.\).

sourceDirectoryNamedestinationDirectoryNameNothing 或空字符串。sourceDirectoryName or destinationDirectoryName is Nothing or an empty string.

该目录不存在。The directory does not exist.

目标目录已存在,并且 overwrite 设置为 FalseThe target directory already exists and overwrite is set to False.

路径超过了系统定义的最大长度。The path exceeds the system-defined maximum length.

操作为循环。The operation is cyclic.

路径中的文件名或目录名包含冒号 (:),或格式无效。A file or directory name in the path contains a colon (:) or is in an invalid format.

该用户缺少查看该路径所必需的权限。The user lacks necessary permissions to view the path.

该用户没有必需的权限。The user does not have required permission.

示例

此示例将 Directory1 移动 Directory2内。This example moves Directory1 inside Directory2.

My.Computer.FileSystem.MoveDirectory("C:\Directory1", "C:\Directory2")

此示例在 Directory2内移动 Directory1,并覆盖目录(如果已存在)。This example moves Directory1 inside Directory2, overwriting the directory if it already exists.

My.Computer.FileSystem.MoveDirectory("C:\Directory1", "C:\Directory2",
True)

注解

如果尝试将目录移动到不存在的目录中,则将创建目标结构。If an attempt is made to move a directory inside a directory that does not exist, the target structure will be created.

另请参阅

MoveDirectory(String, String, UIOption, UICancelOption)

将目录从一个位置移动到另一个位置。Moves a directory from one location to another.

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

参数

sourceDirectoryName
String

要移动的目录的路径。Path of the directory to be moved.

destinationDirectoryName
String

源目录将移到的目录的路径。Path of the directory to which the source directory is being moved.

showUI
UIOption

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

onUserCancel
UICancelOption

指定用户取消操作时是否引发异常。Specifies whether or not an exception is thrown when the user cancels the operation. 默认值为 UICancelOption.ThrowExceptionDefault is UICancelOption.ThrowException.

例外

路径由于以下原因之一无效:是零长度字符串;仅为空白;包含无效字符;是一个设备路径(以 \\.\ 开头)。The path is not valid for one of the following reasons: it is a zero-length string; it contains only white space; it contains invalid characters; or it is a device path (starts with \\.\).

sourceDirectoryNamedestinationDirectoryNameNothing 或空字符串。sourceDirectoryName or destinationDirectoryName is Nothing or an empty string.

该目录不存在。The directory does not exist.

onUserCancel 设置为 ThrowException 并且无法复制子目录中的文件。onUserCancel is set to ThrowException and a subdirectory of the file cannot be copied.

onUserCancel 设置为 ThrowException,并且用户取消了该操作,或者无法完成该操作。onUserCancel is set to ThrowException, and the user cancels the operation, or the operation cannot be completed.

该用户缺少查看该路径所必需的权限。The user lacks necessary permissions to view the path.

路径超过了系统定义的最大长度。The path exceeds the system-defined maximum length.

操作为循环。The operation is cyclic.

路径中的文件名或目录名包含冒号 (:),或格式无效。A file or directory name in the path contains a colon (:) or is in an invalid format.

该用户没有必需的权限。The user does not have required permission.

示例

此示例将 Directory1 移动 Directory2内。This example moves Directory1 inside Directory2.

My.Computer.FileSystem.MoveDirectory("C:\Directory1", "C:\Directory2")

此示例在 Directory2内移动 Directory1,并覆盖目录(如果已存在)。This example moves Directory1 inside Directory2, overwriting the directory if it already exists.

My.Computer.FileSystem.MoveDirectory("C:\Directory1", "C:\Directory2",
True)

注解

如果尝试将目录移动到不存在的目录中,则将创建目标结构。If an attempt is made to move a directory inside a directory that does not exist, the target structure will be created.

另请参阅

适用于