Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))

RenameFile Method

Location

My.Computer.FileSystem.RenameFile

Syntax

My.Computer.FileSystem.RenameFile(path, newName)

path (required; String)

The path to the file to be renamed.

newName (required; String)

The new name of the file. Include the basic filename and extension only; do not include drive, directory, or path information.

Description

The RenameFile method renames an existing file, keeping it in the same directory.

Usage at a Glance

  • The renamed file always remains in the original directory. To move a file to a different directory and rename it at the same time, use the MoveFile method instead.

  • Visual Basic includes a Rename statement that also renames files.

  • An exception is thrown if the path or newName parameters are missing or invalid, or if the newName parameter contains any path-specific information.

  • An exception is thrown if the file does not exist or is in use, or if there is already a file or directory using the new name.

  • An exception is thrown if the user lacks sufficient file-access permissions.

Example

The following example renames a file.

My.Computer.FileSystem.RenameFile("C:\workfile.txt", "playfile.txt")

Related Framework Entries

  • Microsoft.VisualBasic.FileIO.FileSystem.RenameFile Method

  • Microsoft.VisualBasic.MyServices.FileSystemProxy.RenameFile Method

  • System.IO.File.Rename Method

See Also

CopyDirectory Method, CopyFile Method, CreateDirectory Method, DeleteDirectory Method, DeleteFile Method, FileSystem Object, MoveDirectory Method, MoveFile Method, RenameDirectory Method

Категории