Bagikan melalui


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 Snippets Into Your Code (Visual Basic).

Robust Programming

The following conditions can cause an exception:

See Also

Tasks

How to: Copy a Directory to Another Directory in Visual Basic

How to: Parse File Paths in Visual Basic

How to: Move a Directory in Visual Basic

How to: Move the Contents of a Directory in Visual Basic

Reference

My.Computer.FileSystem.RenameDirectory Method