# Name
{: .no_toc }

Renames a disk file, directory, or folder.

Syntax:
> **Name** *oldpathname* **As** *newpathname*

*oldpathname*
: String expression that specifies the existing file name and location; may include directory or folder, and drive.

*newpathname*
: 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.

The **Name** statement renames a file and moves it to a different directory or folder, if necessary. **Name** can move a file across drives, but it can only rename an existing directory or folder when both *newpathname* and *oldpathname* are located on the same drive. **Name** cannot create a new file, directory, or folder.

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

> [!NOTE] BETA 1045
> Each of these failures of **Name** raises run-time error -2147467259 (`&H80004005`), where VB6 raises the numbered error shown:
>
> - 53 (*File not found*) when *oldpathname* does not exist;
> - 58 (*File already exists*) when *newpathname* already exists;
> - 55 (*File already open*) for a file that is open.

### 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.

```tb check_build
Dim oldName, newName
oldName = "OLDFILE": newName = "NEWFILE" ' Define file names.
Name oldName As newName ' Rename file.

oldName = "C:\MYDIR\OLDFILE": newName = "C:\YOURDIR\NEWFILE"
Name oldName As newName ' Move and rename file.
```

### See Also

- [**Kill** statement](/tB/Modules/FileSystem/Kill.md)
- [**FileCopy** procedure](/tB/Modules/FileSystem/FileCopy.md)
- [**MkDir** statement](/tB/Modules/FileSystem/MkDir.md)
- [**RmDir** statement](/tB/Modules/FileSystem/RmDir.md)
