Bewerken

Share via


FileSystem.MoveDirectory Method

Definition

Moves a directory from one location to another.

Overloads

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)

Source:
FileSystem.vb
Source:
FileSystem.vb
Source:
FileSystem.vb

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)

Parameters

sourceDirectoryName
String

Path of the directory to be moved.

destinationDirectoryName
String

Path of the directory to which the source directory is being moved.

Exceptions

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 \\.\).

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.

Examples

This example moves Directory1 inside Directory2.

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

This example moves Directory1 inside Directory2, overwriting the directory if it already exists.

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

Remarks

If an attempt is made to move a directory inside a directory that does not exist, the target structure will be created.

See also

Applies to

MoveDirectory(String, String, UIOption)

Source:
FileSystem.vb
Source:
FileSystem.vb
Source:
FileSystem.vb

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)

Parameters

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. Default is UIOption.OnlyErrorDialogs.

Exceptions

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 \\.\).

sourceDirectoryName or destinationDirectoryName is Nothing or an empty string.

The directory does not exist.

The 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.

Examples

This example moves Directory1 inside Directory2.

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

This example moves Directory1 inside Directory2, overwriting the directory if it already exists.

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

Remarks

If an attempt is made to move a directory inside a directory that does not exist, the target structure will be created.

See also

Applies to

MoveDirectory(String, String, Boolean)

Source:
FileSystem.vb
Source:
FileSystem.vb
Source:
FileSystem.vb

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)

Parameters

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 if existing directories should be overwritten; otherwise False. Default is False.

Exceptions

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 \\.\).

sourceDirectoryName or destinationDirectoryName is Nothing or an empty string.

The directory does not exist.

The 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.

Examples

This example moves Directory1 inside Directory2.

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

This example moves Directory1 inside Directory2, overwriting the directory if it already exists.

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

Remarks

If an attempt is made to move a directory inside a directory that does not exist, the target structure will be created.

See also

Applies to

MoveDirectory(String, String, UIOption, UICancelOption)

Source:
FileSystem.vb
Source:
FileSystem.vb
Source:
FileSystem.vb

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)

Parameters

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. Default is UIOption.OnlyErrorDialogs.

onUserCancel
UICancelOption

Specifies whether or not an exception is thrown when the user cancels the operation. Default is UICancelOption.ThrowException.

Exceptions

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 \\.\).

sourceDirectoryName or destinationDirectoryName is Nothing or an empty string.

The directory does not exist.

onUserCancel is set to ThrowException and a subdirectory of the file cannot be copied.

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.

Examples

This example moves Directory1 inside Directory2.

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

This example moves Directory1 inside Directory2, overwriting the directory if it already exists.

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

Remarks

If an attempt is made to move a directory inside a directory that does not exist, the target structure will be created.

See also

Applies to