Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Name" function for renaming files/directories

Status
Not open for further replies.

zandsc1

Programmer
Nov 12, 2008
53
US
All -

I'm using the built in "Name" function for VBA to rename some files and directories but running into issues. The directories and files that I'm editing are on my local network, and I'm having some success but I'm not where I want to be yet.

When I rename the file:
Name "\\DavesComputer\Subdirectory1\Subdirectory2\Word.doc" As "\\DavesComputer\Subdirectory1\Subdirectory2\Word1.doc"

I get no problems. The files are renamed correctly and I have no errors.

When I try to rename the subdirectory:
Name "\\DavesComputer\Subdirectory1\Subdirectory2" As "\\DavesComputer\Subdirectory1\Subdirectory3" I get a path/file error.

Anyone have pearls of wisdom? By the way I am running a routine to test if there are open files in the directory before I rename it, and that's not the issue here (I believe that would throw a different error anyway).

Thanks.
 
Hallo,

What is the exact code you are using for each example?

- Frink
 
No open file(s) into Subdirectory2 when you try to rename it ?
No preexisting Subdirectory3 ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I think you want the Move method.

Step 1. Set up an object to receive the folder definition
Step 2. Assign the folder path to the object
Step 3. Move the object folder to the new destination (can be the same location!) and give it a new name

like so:
Code:
Dim oFSObject, oTargetFolder as Object

set oFSObject = CreateObject("Scripting.FileSystemObject")
set oTargetFolder = oFSObject.GetFolder("\\DavesComputer\Subdirectory1\Subdirectory2")

oTargetFolder.Move "\\DavesComputer\Subdirectory1\Subdirectory3"
 
Thanks Gruuuu, I'll try that. I'm still not certain why my 'Name' function keeps failing when I'm using the directory even though it works fine when I'm renaming a file in that directory. I am running a routine to check for locked files before I do the rename. I've tested it and it works so I'm certain there are no open files. (There's only 1 or 2 files in the subdirectory to begin with).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top