This documentation is archived and is not being maintained.

FileSystem.MoveFile Method (String, String, Boolean)

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,
	bool overwrite


Type: System.String

String. Path of the file to be moved. Required.

Type: System.String

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

Type: System.Boolean

Boolean. Specifies whether to overwrite existing files. Default is False. Required.

For more detailed information, see the Visual Basic topic My.Computer.FileSystem.MoveFile Method.

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 examples of tasks involving the My.Computer.FileSystem.MoveFile method.

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

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0