Name Statement

Description

Renames a disk file, directory, or folder.

Syntax

Name oldpathname As newpathname

The Name statement syntax has these parts:

Part

Description

oldpathname

Required. String expression that specifies the existing file name and location — may include directory or folder, and drive.

newpathname

Required. String expression that specifies the new file name and location — may include directory or folder, and drive. The file name specified by newpathname can't already exist.


Remarks

Both newpathname and oldpathname must be on the same drive. If the path in newpathname exists and is different from the path in oldpathname, the Name statement moves the file to the new directory or folder and renames the file, if necessary. If newpathname and oldpathname have different paths and the same file name, Name moves the file to the new location and leaves the file name unchanged. Using Name, you can move a file from one directory or folder to another, but you can't move a directory or folder.

Using Name on an open file produces an error. You must close an open file before renaming it. Name arguments cannot include multiple-character (*) and single-character (?) wildcards.

See Also

Kill statement.

Example

This example uses the Name statement to rename a file. For purposes of this example, assume that the directories or folders that are specified already exist.

Dim OldName, NewName
OldName = "OLDFILE": NewName = "NEWFILE"    ' Define filenames.
Name OldName As NewName                    ' Rename file.

' In Microsoft Windows:
OldName = "C:\MYDIR\OLDFILE": NewName = "C:\YOURDIR\NEWFILE"
Name OldName As NewName                    ' Move and rename file.

' On the Macintosh:
OldName = "HD:MY FOLDER:OLDFILE": NewName = "HD:YOUR FOLDER:NEWFILE"
Name OldName As NewName                    ' Move and rename file.