Renameoldpath newpath

The Rename() function renames a disk file or folder. The existing file's or folder's name is specified by the oldpath argument, and the new name is specified with the newpath argument. The path specified by the newpath argument should not exist already. The statement

Rename("C:\Users", "C:\All Users")

will rename the folder C:\Users to C:\All Users. The folder will be renamed even if it contains sub-folders and/or files. If you attempt to rename two nested folders at once with a statement like the following one:

Rename("C:\Users\New User", "C:\All Users\User1")

a runtime error will be generated. Rename them one at a time (it doesn't make any difference which one is renamed first).

The Rename() function can rename a file and move it to a different directory or folder, if necessary. However, it can't move a folder (with or without its subfolders and files). If the folder D:\New User folder exists, the following statement will move the file UserProfile.cps to the folder New User on the D: drive and rename it as well:

Rename("C:\A11Users\User1\Profi1e1.cps", "D:\New User\UserProfile.eps")

If the folder D:\New User does not exist, it will not be created automatically. You must first create it, then move the file there. The RenameQ function cannot create a new folder.

Notice that the RenameQ function can not act on an open file. You must first close it, then rename it. Like most file- and folder-manipulation statements of Visual Basic, the Rename function's arguments don't recognize wildcards.

0 0

Post a comment