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
newpathmust not already exist, or an error will be generated.oldpathmust exist; the Rename procedure isn’t able to create a new file or directory.When renaming a file or folder, both
newpathandoldpathshould 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
newpathandoldpathcan 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.newpathandoldpathcan be on different drives, but if they are, Rename cannot both move the files and rename them.newpathandoldpathcannot 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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access