Results 1 to 2 of 2
Thread: Copy File Script
2004-01-23, 14:10 #1
- Join Date
- Apr 2002
- Arkansas, USA
- Thanked 0 Times in 0 Posts
Copy File Script
Can someone let me know the proper syntax for creating a VB script to copy a file from a network computer to their desktop. I tried the following which I found on Microsoft Tech Net but got an error stating Path not found. I used
Const OverwriteExisting = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "wd-97G8611_bbShareRoederReport03.xls" , "Cocuments and Settings%USERNAME%Desktop", OverwriteExisting
I can access the network computer from the cmd prompt so the path is valid, and the folder and file is properly shared.
I want to be able to send a script to a few other users so they can easily copy this file to their own desktop. The file is large and I want to avoid having to email it.
2004-01-24, 05:50 #2
- Join Date
- Feb 2001
- Silicon Valley, USA
- Thanked 94 Times in 90 Posts
Re: Copy File Script
I think there is a problem with the %USERNAME% parameter being in the middle of a literal string. Does it work if you substitute in a known username? If so, I think you have two options: (1) construct the string using the parameter, e.g.
objFSO.CopyFile "wd-97G8611_bbShareRoederReport03.xls" , "Cocuments and Settings" & %USERNAME% & "Desktop", OverwriteExisting
...although I suspect that the VBScript interpreter won't know what %USERNAME% is...
or (2) use the Shell object to retrieve the user's desktop folder. Here's an example:
<UL>Dim objShell, strDesktopPath
Set objShell = Wscript.CreateObject("Wscript.Shell") 'Instantiate Windows Shell object
strDesktopPath = objShell.SpecialFolders("Desktop")
If Not (objShell Is Nothing) Then Set objShell = Nothing[/list]Hope this helps.