RenameFile Method


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




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net