FileSystem.RenameDirectory Method (String, String)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Renames a directory.

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

public static void RenameDirectory(
	string directory,
	string newName
)

Parameters

directory
Type: System.String

Path and name of directory to be renamed.

newName
Type: System.String

New name for directory.

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

ArgumentException

newName contains path information.

ArgumentNullException

directory is Nothing.

-or-

newName is Nothing or an empty string.

DirectoryNotFoundException

The directory does not exist.

IOException

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

PathTooLongException

The path exceeds 248 characters.

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.

UnauthorizedAccessException

The user does not have required permission.

This method cannot be used to move a directory; use the MoveDirectory method to move and rename the directory.

This example renames the Test directory to SecondTest.

My.Computer.FileSystem.RenameDirectory("C:MyDocuments\Test", "SecondTest")

FileIOPermission

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

.NET Framework
Available since 2.0
Return to top
Show: