copying files. 
Author Message
 copying files.

How can I copy a file from a network server to a users computer using the
special folders object?

I tried using:
set WshShell = WScript.CreateObject("WScript.Shell")
Set strFileCopyTo = WshShell.SpecialFolders("Startup")
Set fso = CreateObject("Scripting.FileSystemObject")
Set HtaFile = FSO.GetFile("\\Server1\moleroot\desktop_final.hta")

HtaFile.Copy(strFileCopyTo)

but the fourth line gives me an error.

Any ideas. (WSH is new groud for me)
Thanks
ES



Tue, 02 Sep 2003 00:34:04 GMT  
 copying files.
E,

Your problem is in the following line:

    Set strFileCopyTo = WshShell.SpecialFolders("Startup")

The 'Set' keyword is used when returning an object reference, not a regular
data type like a string.  Because .SpecialFolders returns the path to the
folder as a string, remove 'Set' so your line reads:

    strFileCopyTo = WshShell.SpecialFolders( "Startup" )

The next thing you might need to do (I didnt' test your code) is to add a
backslash to strFileCopyTo so the copy method knows you're trying to copy to
a folder.

An easier way to accomplish what you want is to use the FSO.CopyFile method
as follows:

Set FSO = CreateObject( "Scripting.FileSystemObject" )
Set Shell = CreateObject( "WScript.Shell" )

strSource = "\\server1\moleroot\desktop_final.hta"

' get the startup folder and append a backslash if necessary
strDest =  FSO.BuildPath( Shell.SpecialFolders( "Startup" ), "\" )

FSO.CopyFile strSource, strDest

Hope this helps.

Matt.


Quote:
> How can I copy a file from a network server to a users computer using the
> special folders object?

> I tried using:
> set WshShell = WScript.CreateObject("WScript.Shell")
> Set strFileCopyTo = WshShell.SpecialFolders("Startup")
> Set fso = CreateObject("Scripting.FileSystemObject")
> Set HtaFile = FSO.GetFile("\\Server1\moleroot\desktop_final.hta")

> HtaFile.Copy(strFileCopyTo)

> but the fourth line gives me an error.

> Any ideas. (WSH is new groud for me)
> Thanks
> ES



Tue, 02 Sep 2003 09:23:43 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Copying Files in Jscript using File Collection

2. Copying files to c:\program files\

3. File security when move/copy files

4. create directory, copy files, run exe files

5. Copying Files With Specific File Extension

6. Copying files from a Web server using clientside vbscript

7. Copy files and folders VBScript

8. Security warning when copying file with Jscript!

9. creating a vb script to copy file accross a network to nt workstation

10. Copy Files using FileSystemObject (Doesn't work)

11. Copy file from local machine to web host

12. Copying Files on Network Drive

 

 
Powered by phpBB® Forum Software