Results 1 to 2 of 2
  1. #1
    2 Star Lounger
    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.


  2. #2
    Super Moderator jscher2000's Avatar
    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")
    MsgBox strDesktopPath
    If Not (objShell Is Nothing) Then Set objShell = Nothing[/list]Hope this helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts