Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Renames a directory.
' Usage
My.Computer.FileSystem.RenameDirectory(directory ,newName)
' Declaration
Public Sub RenameDirectory( _
   ByVal directory As String, _
   ByVal newName As String _
)
Parameters
- directory 
 String. Path and name of directory to be renamed. Required.
- newName 
 String. New name for directory. Required.
Exceptions
The following conditions may cause an exception:
- 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). 
- The newName parameter contains path information (ArgumentException). 
- The path is not valid because it is Nothing (ArgumentNullException). 
- The newName parameter is Nothing or an empty string (ArgumentNullException). 
- The source directory is not valid or does not exist (DirectoryNotFoundException). 
- There is an existing file or directory with the name specified in newName (IOException). 
- The directory is a root directory (IOException). 
- The path exceeds 248 characters (PathTooLongException). 
- A file or directory name in the path contains a colon (:) or is in an invalid format (NotSupportedException). 
- The user lacks necessary permissions to view the path (SecurityException). 
- The user does not have required permission (UnauthorizedAccessException). 
Remarks
This method cannot be used to move a directory; use the MoveDirectory method to move and rename the directory.
Tasks
The following table lists an example of a task involving the My.Computer.FileSystem.RenameDirectory method.
| To | See | 
|---|---|
| Rename a directory | 
Example
This example renames the Test directory to SecondTest.
My.Computer.FileSystem.RenameDirectory("C:MyDocuments\Test", "SecondTest")
Requirements
Namespace:Microsoft.VisualBasic.MyServices
Class:FileSystemProxy (provides access to FileSystem)
Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)
Availability by Project Type
| Project type | Available | 
|---|---|
| Windows Application | Yes | 
| Class Library | Yes | 
| Console Application | Yes | 
| Windows Control Library | Yes | 
| Web Control Library | Yes | 
| Windows Service | Yes | 
| Web Site | Yes | 
Permissions
The following permission may be necessary:
| Permission | Description | 
|---|---|
| Controls the ability to access files and folders. Associated enumeration: Unrestricted. | 
For more information, see Code Access Security and Requesting Permissions.
See Also
Tasks
How to: Parse File Paths in Visual Basic
Reference
My.Computer.FileSystem.MoveDirectory Method
Other Resources
Creating, Deleting, and Moving Files and Directories in Visual Basic