Export (0) Print
Expand All

FileSystem.MoveDirectory Method (String, String, UIOption, UICancelOption)

Moves a directory from one location to another.

Namespace:  Microsoft.VisualBasic.FileIO
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)

public static void MoveDirectory(
	string sourceDirectoryName,
	string destinationDirectoryName,
	UIOption showUI,
	UICancelOption onUserCancel
)

Parameters

sourceDirectoryName
Type: System.String

Path of the directory to be moved.

destinationDirectoryName
Type: System.String

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

showUI
Type: Microsoft.VisualBasic.FileIO.UIOption

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

onUserCancel
Type: Microsoft.VisualBasic.FileIO.UICancelOption

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

ExceptionCondition
ArgumentException

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

ArgumentNullException

sourceDirectoryName or destinationDirectoryName is Nothing or an empty string.

ArgumentNullException

sourceDirectoryName or destinationDirectoryName is Nothing or an empty string.

DirectoryNotFoundException

The directory does not exist.

IOException

The source is a root directory or The source path and the target path are the same.

IOException

The target directory already exists and overwrite is set to False.

IOException

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

OperationCanceledException

onUserCancel is set to ThrowException, and the user cancels the operation, or the operation cannot be completed.

SecurityException

onUserCancel is set to ThrowException, and the user lacks necessary permissions.

PathTooLongException

The path exceeds the system-defined maximum length.

InvalidOperationException

The operation is cyclic.

NotSupportedException

A file or directory name in the path contains a colon (:) or is in an invalid format.

SecurityException

The user lacks necessary permissions to view the path.

UnauthorizedAccessException

The user does not have required permission.

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

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)

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft