My.Computer.FileSystem.MoveDirectory Method

Moves a directory from one location to another.

' Usage
My.Computer.FileSystem.MoveDirectory(sourceDirectoryName ,destinationDirectoryName)
My.Computer.FileSystem.MoveDirectory(sourceDirectoryName ,destinationDirectoryName ,overwrite)
My.Computer.FileSystem.MoveDirectory(sourceDirectoryName ,destinationDirectoryName ,showUI)
My.Computer.FileSystem.MoveDirectory(sourceDirectoryName ,destinationDirectoryName ,showUI ,onUserCancel)

' Declaration
Public Sub MoveDirectory( _
   ByVal sourceDirectoryName As String, _
   ByVal destinationDirectoryName As String _
)
' -or-
Public Sub MoveDirectory( _
   ByVal sourceDirectoryName As String, _
   ByVal destinationDirectoryName As String, _
   ByVal overwrite As Boolean _
)
' -or-
Public Sub MoveDirectory( _
   ByVal sourceDirectoryName As String, _
   ByVal destinationDirectoryName As String, _
   ByVal showUI As UIOption _
)
' -or-
Public Sub MoveDirectory( _
   ByVal sourceDirectoryName As String, _
   ByVal destinationDirectoryName As String, _
   ByVal showUI As UIOption, _
   ByVal onUserCancel As UICancelOption _
)

Parameters

  • sourceDirectoryName
    String. Path of the directory to be moved. Required.

  • destinationDirectoryName
    String. Path of the directory to which the source directory is being moved. Required.

  • overwrite
    Boolean. Specifies whether existing directories should be overwritten. Default is False. Required.

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

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

Exceptions

The following conditions may cause an exception:

Remarks

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

Tasks

The following table lists an example of a task involving the My.Computer.FileSystem.MoveDirectory method.

To

See

Move a directory

How to: Move a Directory in Visual Basic

Example

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)

Requirements

Namespace:Microsoft.VisualBasic.MyServices

Class:FileSystemProxy (provides access to FileSystem)

Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

Availability by Project Type

Project type

Available

Windows Application

Yes

Class Library

Yes

Console Application

Yes

Windows Control Library

Yes

Web Control Library

Yes

Windows Service

Yes

Web Site

Yes

Permissions

The following permissions may be necessary:

Permission

Description

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.

For more information, see Code Access Security and Requesting Permissions.

See Also

Reference

My.Computer.FileSystem Object

UIOption Enumeration

UICancelOption Enumeration

My.Computer.FileSystem.MoveFile Method

My.Computer.FileSystem.CopyDirectory Method

Other Resources

Creating, Deleting, and Moving Files and Directories in Visual Basic