MoveDirectory Method (My.Computer.FileSystem Object)
TOC
Collapse the table of content
Expand the table of content
The document is archived and information here might be outdated

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 _
)

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.

The following conditions may cause an exception:

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

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

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)

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

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.

Show:
© 2016 Microsoft