FileSystem.MoveFile FileSystem.MoveFile FileSystem.MoveFile FileSystem.MoveFile Method

Definition

Moves a file to a new location.

Overloads

MoveFile(String, String) MoveFile(String, String) MoveFile(String, String) MoveFile(String, String)

Moves a file to a new location.

MoveFile(String, String, UIOption) MoveFile(String, String, UIOption) MoveFile(String, String, UIOption) MoveFile(String, String, UIOption)

Moves a file to a new location.

MoveFile(String, String, Boolean) MoveFile(String, String, Boolean) MoveFile(String, String, Boolean) MoveFile(String, String, Boolean)

Moves a file to a new location.

MoveFile(String, String, UIOption, UICancelOption) MoveFile(String, String, UIOption, UICancelOption) MoveFile(String, String, UIOption, UICancelOption) MoveFile(String, String, UIOption, UICancelOption)

Moves a file to a new location.

MoveFile(String, String) MoveFile(String, String) MoveFile(String, String) MoveFile(String, String)

Moves a file to a new location.

public:
 static void MoveFile(System::String ^ sourceFileName, System::String ^ destinationFileName);
public static void MoveFile (string sourceFileName, string destinationFileName);
static member MoveFile : string * string -> unit
Public Shared Sub MoveFile (sourceFileName As String, destinationFileName As String)

Parameters

sourceFileName
String String String String

Path of the file to be moved.

destinationFileName
String String String String

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

Exceptions

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.

destinationFileName is Nothing or an empty string.

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

The path exceeds the system-defined maximum length.

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

The user lacks necessary permissions to view the path.

Examples

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

Remarks

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

Security

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.

MoveFile(String, String, UIOption) MoveFile(String, String, UIOption) MoveFile(String, String, UIOption) MoveFile(String, String, UIOption)

Moves a file to a new location.

public:
 static void MoveFile(System::String ^ sourceFileName, System::String ^ destinationFileName, Microsoft::VisualBasic::FileIO::UIOption showUI);
public static void MoveFile (string sourceFileName, string destinationFileName, Microsoft.VisualBasic.FileIO.UIOption showUI);
static member MoveFile : string * string * Microsoft.VisualBasic.FileIO.UIOption -> unit
Public Shared Sub MoveFile (sourceFileName As String, destinationFileName As String, showUI As UIOption)

Parameters

sourceFileName
String String String String

Path of the file to be moved.

destinationFileName
String String String String

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

showUI
UIOption UIOption UIOption UIOption

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

Exceptions

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.

destinationFileName is Nothing or an empty string.

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

The path exceeds the system-defined maximum length.

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

The user lacks necessary permissions to view the path.

Examples

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

Remarks

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

Security

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.

See also

MoveFile(String, String, Boolean) MoveFile(String, String, Boolean) MoveFile(String, String, Boolean) MoveFile(String, String, Boolean)

Moves a file to a new location.

public:
 static void MoveFile(System::String ^ sourceFileName, System::String ^ destinationFileName, bool overwrite);
public static void MoveFile (string sourceFileName, string destinationFileName, bool overwrite);
static member MoveFile : string * string * bool -> unit
Public Shared Sub MoveFile (sourceFileName As String, destinationFileName As String, overwrite As Boolean)

Parameters

sourceFileName
String String String String

Path of the file to be moved.

destinationFileName
String String String String

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

overwrite
Boolean Boolean Boolean Boolean

True to overwrite existing files; otherwise False. Default is False.

Exceptions

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.

destinationFileName is Nothing or an empty string.

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

The path exceeds the system-defined maximum length.

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

The user lacks necessary permissions to view the path.

Examples

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

Remarks

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

Security

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.

MoveFile(String, String, UIOption, UICancelOption) MoveFile(String, String, UIOption, UICancelOption) MoveFile(String, String, UIOption, UICancelOption) MoveFile(String, String, UIOption, UICancelOption)

Moves a file to a new location.

public:
 static void MoveFile(System::String ^ sourceFileName, System::String ^ destinationFileName, Microsoft::VisualBasic::FileIO::UIOption showUI, Microsoft::VisualBasic::FileIO::UICancelOption onUserCancel);
public static void MoveFile (string sourceFileName, string destinationFileName, Microsoft.VisualBasic.FileIO.UIOption showUI, Microsoft.VisualBasic.FileIO.UICancelOption onUserCancel);
static member MoveFile : string * string * Microsoft.VisualBasic.FileIO.UIOption * Microsoft.VisualBasic.FileIO.UICancelOption -> unit
Public Shared Sub MoveFile (sourceFileName As String, destinationFileName As String, showUI As UIOption, onUserCancel As UICancelOption)

Parameters

sourceFileName
String String String String

Path of the file to be moved.

destinationFileName
String String String String

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

showUI
UIOption UIOption UIOption UIOption

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

onUserCancel
UICancelOption UICancelOption UICancelOption UICancelOption

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

Exceptions

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.

destinationFileName is Nothing or an empty string.

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

onUserCancel is set to ThrowException, and either the user has cancelled the operation or an unspecified I/O error occurs.

The path exceeds the system-defined maximum length.

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

The user lacks necessary permissions to view the path.

Examples

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

Remarks

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

Security

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.

See also

Applies to