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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Path not found?

Status
Not open for further replies.

bizybeaver

Technical User
Apr 7, 2004
26
US
I have a simple script to copy a file from a server (network) to a local machine.

I am in a Windows domain and I can't use a mapped drive letter as this would be used by several people. I figured I could copy a file directly by using \\server\folder\etc but my code just stops and says Path not found. If I copy and paste it into IE, for example, it works.

Do I have to have a mapped drive? Or is there a way I can supply the current user ADID and password to gain access and map a drive and then discconect it?

Dim sh
Dim strFolder
Dim objFSO

set sh = CreateObject("WScript.Shell")
strFolder = "C:\Documents and Settings\%UserName%\Application Data\Microsoft\Templates"
Const OverwriteExisting = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "\\kceiscp202a\bus_sale_dev\Copy Test.doc", strFolder & "\", OverwriteExisting

Set sh = Nothing
Set strFolder = Nothing
Set objFSO = Nothing
 
I'm betting that your problem is with the variable of %UserName%.

Profile paths are not always the same as the username. For example a user who has a local profile before a domain profile will get a domain profile of username.001.

Take a look at manipulating the Special Folders path. You should be able to grab the path for the desktop, strip it back 7 characters and add in \Application Data\Microsoft\Templates.

I hope you find this post helpful.

Regards,

Mark
 
Is "Copy Test.Doc" the actual name of the file?
which path can't it find - the network or local?
add:
On error resume next
objFSO.CopyFile "\\kceiscp202a\bus_sale_dev\Copy Test.doc", strFolder & "\", OverwriteExisting
If err <> 0 Then wsh.echo err.number,err.description
 
If you want to use the %UserName% env variable, then look at the .ExpandEnvironmentString method.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Ok, I added teh code form mharcourt, and it gives me a message "76 Path not found"

markdmac, so you're saying I should abandon %UserName% and use SpecialFolders("Desktop") & "\Application Data\Microsoft\Templates"

Ok, I tried it witih Special Folders and it did copy to my desktop. :)

How do I back up "7 spaces" and reattach the path to the templates, though? THANKS so much!
 
How do I back up "7 spaces" and reattach the path to the templates, though?"

Look at the Left() function and the Len() function to back up. Just use a concatenation operator & or + to concatenate the strings together to reattach the path to the templates.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Of course the backing it up 7 spaces method is based on the assumption that your desktop folder is located at C:\Documents And Settings\USERNAME\Desktop. At my work that is not the case since we use network locations for home directories.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Code:
dim WSHShell, objFSO, desktop, pathstring, Rootpath, TemplatePath

Set WSHshell = CreateObject("WScript.Shell")
set objFSO=CreateObject("Scripting.FileSystemObject")

desktop = WSHShell.SpecialFolders("Desktop")
pathstring = objFSO.GetAbsolutePathName(desktop)
RootPath=Left(pathstring,(len(pathstring)-7))
TemplatePath = RootPath & "Application Data\Microsoft\Templates"
WScript.Echo TemplatePath

I hope you find this post helpful.

Regards,

Mark
 
Thanks so much. It does seem to work, but now I get a permission denied when copying. Why would that be?

dim WSHShell, objFSO, desktop, pathstring, Rootpath, TemplatePath

Set WSHshell = CreateObject("WScript.Shell")
set objFSO=CreateObject("Scripting.FileSystemObject")

desktop = WSHShell.SpecialFolders("Desktop")
pathstring = objFSO.GetAbsolutePathName(desktop)
RootPath=Left(pathstring,(len(pathstring)-7))
TemplatePath = RootPath & "\Application Data\Microsoft\Templates"

On error resume next

objFSO.CopyFile "\\kceiscp202a\bus_sale_dev\Copy Test.doc", TemplatePath, OverwriteExisting
If err <> 0 Then wsh.echo err.number,err.description
 
What is the path displayed if you put this line:

WScript.Echo TemplatePath

Right before the line that does the copy?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Your user probably does not have permissions to either the source or destination folders. Check NTFS settings.

I hope you find this post helpful.

Regards,

Mark
 
I get the exact path I need with the WScript.Echo.

When I replace it with the CopyFile, it says access denied. I did get the last bit of code to work and it did copy to my desktop. I have full Admin rights to this local test machine, so something else must be awry. If I got it to my desktop, I should be able to get it into the template folder. I'm baffled.
 
Is there a copy of the file already in the destination directroy? If so, is that copy open?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
No, no copy is allready there, besides wouldn't the Overwrite attribute take care of that?
I guess another way I'm going to attempt is copy it to the desktop and then try moving it to that folder. This is just bizzare.
 
The overwrite would take care of it if there was simply a copy already there, but I don't think it would work if there was a copy there and an application had the file open.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
STUPID ME! I forgot a \ at the end of my path.

Syntax drives me nuts sometimes.

Thanks to all for your help!

Tom, you also said something about ExpandEnvironmentString. I just wanted to research that so I can become more aware of code. Is there a link you can refer me to for more info about using this instead?

Thanks again to everyone!
 
It is in the WSH documentation which you can easily find through google. You can find tons of examples by searching this forum.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
You can see what env variables are available to you by typing SET at a command prompt.

I hope you find this post helpful.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top