VB.NET Language in a Nutshell
| Rename Procedure |
Class
Microsoft.VisualBasic.FileSystem
Syntax
Rename( oldpath , newpath )
- oldpath (required; String)
-
The current filename and optional path
- newpath (required; String)
-
The new filename and optional path
Description
Renames a disk file or folder
Rules at a Glance
-
newpath must not already exist, or an error will be generated.
-
oldpath must exist; the Rename procedure isn't able to create a new file or directory.
-
When renaming a file or folder, both newpath and oldpath should include a path to the same folder, or the function will move the file or directory. For instance, the statement:
Rename("c:\Temp\Graphics", "Images")
renames the Graphics folder to Images and moves it so that it becomes a subdirectory of the current directory.
-
Path information included in newpath and oldpath can take the form of the local system's path or the UNC path. The local system path can be either a fully qualified path or a relative path from the current directory.
-
newpath and oldpath can be on different drives , but if they are, Rename cannot both move the files and rename them.
-
newpath and oldpath cannot include the wildcard characters ? and * .
-
You cannot use the Rename procedure with a file that is already open .
Programming Tips and Gotchas
The Rename procedure can be used to move a file from one folder to another and, optionally , to change the file's name at the same time. If the folder specified in newname exists and is different from that stated in oldname , the file will be moved to the folder specified in newname . If the filename in newname is also different, the file will be renamed at the same time.
VB.NET/VB 6 Differences
The Rename procedure is new to VB.NET.