Renames a disk file, directory, or folder.
Public Sub Rename( _ ByVal OldPath As String, _ ByVal NewPath As String _ )
Exception type | Error number | Condition |
---|---|---|
5 | Pathname is invalid . | |
53 | OldPath file does not exist. | |
58 | NewPath file already exists. | |
75 | Access is invalid. | |
Cannot rename to different device. |
The Rename function renames a file and moves it to a different directory or folder, if necessary. The Rename function can move a file across drives, but it can only rename an existing directory or folder when both NewPath and OldPath are located on the same drive. Name cannot create a new file, directory, or folder.
Using the Rename function on an open file produces an error. You must close an open file before renaming it. Rename arguments cannot include multiple-character (*) and single-character (?) wildcards.
This example uses the Rename function to rename a file. For purposes of this example, assume that the directories or folders that are specified already exist.
Dim OldName, NewName As String OldName = "OLDFILE" NewName = "NEWFILE" ' Define file names. Rename(OldName, NewName) ' Rename file. OldName = "C:\MYDIR\OLDFILE" NewName = "C:\YOURDIR\NEWFILE" Rename(OldName, NewName) ' Move and rename file.
Kill Function |