How to: Rename a Directory in Visual Basic

The RenameDirectory method of the My.Computer.FileSystem object can be used to rename a directory by supplying the current location and name of the directory, along with the new name for the directory. This method cannot be used to move a directory; use the MoveDirectory method to move and rename the directory.

To rename a directory

  • Use the My.Computer.FileSystem.RenameDirectory method to rename a directory. The following code renames the Test directory to SecondTest.

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

This code example is also available as an IntelliSense code snippet. In the code snippet picker, the example is located in File system - Processing Drives, Folders, and Files. For more information, see How to: Insert IntelliSense Code Snippets.

The following conditions can cause an exception:

Community Additions

ADD
Show: