Name
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
andoldpath
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
andoldpath
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
andoldpath
can be on different drives, but if they are, Rename cannot both move the files and rename them.newpath
andoldpath
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 ...
Get VB.NET Language in a Nutshell, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.