FileSystem.MoveFile Method (String, String, UIOption)

 

Moves a file to a new location.

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

public static void MoveFile(
	string sourceFileName,
	string destinationFileName,
	UIOption showUI
)

Parameters

sourceFileName
Type: System.String

Path of the file to be moved.

destinationFileName
Type: System.String

Path of the directory into which the file should be moved.

showUI
Type: Microsoft.VisualBasic.FileIO.UIOption

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

Exception Condition
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 \\.\); it ends with a trailing slash.

ArgumentNullException

destinationFileName is Nothing or an empty string.

FileNotFoundException

The source file is not valid or does not exist.

IOException

The destination file exists and overwrite is set to False.

IOException

The file is in use by another process, or an I/O error occurs.

PathTooLongException

The path exceeds the system-defined maximum length.

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.

If the target structure does not exist, it is created.

The MoveFile method preserves ACEs (Access Control Entries) only when moving the file within the same volume. This includes inherited ACEs, which become direct ACEs when moved (direct ACEs take precedence over inherited ACEs). If a file is moved between volumes, ACEs will not be copied.

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

To

See

Move a file

How to: Move a File in Visual Basic

This example moves the file Test.txt from TestDir1 to TestDir2.

My.Computer.FileSystem.MoveFile("C:\TestDir1\test.txt", "C:\TestDir2\test.txt")

This example moves the file Test.txt from TestDir1 to TestDir2 and renames it Test2.txt.

My.Computer.FileSystem.MoveFile("C:\TestDir1\test.txt", "C:\TestDir2\test2.txt")

EnvironmentPermission

Controls the ability to access all environment variables. Associated enumeration: Unrestricted.

FileIOPermission

Controls the ability to access files and folders. Associated enumeration: Unrestricted.

RegistryPermission

Controls the ability to access registry variables. Associated enumeration: Unrestricted.

UIPermission

Controls the permissions related to user interfaces and the clipboard. Associated enumeration: SafeSubWindows.

.NET Framework
Available since 2.0
Return to top
Show: