This documentation is archived and is not being maintained.

FileSystem.RenameFile Method

Renames a file.

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

public static void RenameFile(
	string file,
	string newName


Type: System.String
File to be renamed.
Type: System.String
New name of file.


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 \\.\).


newName contains path information or ends with a backslash (\).


file is Nothing.


newName is Nothing or an empty string.


The directory does not exist.


There is an existing file or directory with the name specified in newName.


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.


The user does not have required permission.

This method cannot be used to move a file; use the MoveFile method to move and rename the file.

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

This example renames the file Test.txt to SecondTest.txt.

My.Computer.FileSystem.RenameFile("C:\Test.txt", "SecondTest.txt")

Change "C:\Test.txt" to the path and file name of the file that you want to rename.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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