Batch file operation copies files to desktop - Microsoft Windows

This is a discussion on Batch file operation copies files to desktop - Microsoft Windows ; Hi, I would like to write a batch file that can do the following: -Copy two files (an .mdb and a .bat) from a location on the network given as an UNC path (e.g. \\servername\sharename\...\myFile.mdb) and save it to the ...

+ Reply to Thread
Results 1 to 8 of 8

Thread: Batch file operation copies files to desktop

  1. Batch file operation copies files to desktop

    Hi,

    I would like to write a batch file that can do the following:

    -Copy two files (an .mdb and a .bat) from a location on the network
    given as an UNC path (e.g. \\servername\sharename\...\myFile.mdb) and
    save it to the currently logged on user's desktop, using the generic
    Windows location for whether it is 98, NT or XP.

    Anybody know how to do this? Thanks in advance.

    Regards,
    Jean


  2. Re: Batch file operation copies files to desktop

    jeanjanssens@hotmail.com wrote:

    > Hi,
    >
    > I would like to write a batch file that can do the following:
    >
    > -Copy two files (an .mdb and a .bat) from a location on the network
    > given as an UNC path (e.g. \\servername\sharename\...\myFile.mdb) and
    > save it to the currently logged on user's desktop, using the generic
    > Windows location for whether it is 98, NT or XP.
    >
    > Anybody know how to do this? Thanks in advance.
    >
    > Regards,
    > Jean
    >


    If you run the batchfile from the machine the user is logged in this
    should not be too hard.

    You can manually create a file somewhere to do the identification of the
    OS type and thus the location of the desktop folder, and use like an if
    and goto system, or try and use some built-in variables to determine the
    OS type.

    Wim

  3. Re: Batch file operation copies files to desktop

    On 14 Apr 2005 06:05:49 -0700, jeanjanssens@hotmail.com wrote:

    >Hi,
    >
    >I would like to write a batch file that can do the following:
    >
    >-Copy two files (an .mdb and a .bat) from a location on the network
    >given as an UNC path (e.g. \\servername\sharename\...\myFile.mdb) and
    >save it to the currently logged on user's desktop, using the generic
    >Windows location for whether it is 98, NT or XP.
    >
    >Anybody know how to do this? Thanks in advance.
    >
    >Regards,
    >Jean


    With Win2K / WinXP you can use the %HOMEPATH% variable in a batch file
    to point to the current user's desktop. Thus If user JoeBob is logged
    in, the command

    Copy \\SERVER\myfile.mdb "%HOMEPATH%\Desktop"

    will copy the file MYFILE.MDB from the server onto his desktop.

    Note the quites around the destination; since the default home
    directory for Win2K/XP is the "Documents and Settings" folder, you
    need quotes to handle the long-filename-with-spaces

    I'm not sure about Windows9x...



  4. Re: Batch file operation copies files to desktop

    > With Win2K / WinXP you can use the %HOMEPATH% variable in a batch file
    > to point to the current user's desktop. Thus If user JoeBob is logged
    > in, the command
    >
    > Copy \\SERVER\myfile.mdb "%HOMEPATH%\Desktop"
    >
    > will copy the file MYFILE.MDB from the server onto his desktop.
    >
    > Note the quites around the destination; since the default home
    > directory for Win2K/XP is the "Documents and Settings" folder, you
    > need quotes to handle the long-filename-with-spaces
    >
    > I'm not sure about Windows9x...
    >


    Windows 9x should use C:\Windows\Desktop normally, but if you have
    enabled profiles it could be C:\Windows\profiles\username\Desktop

  5. Re: Batch file operation copies files to desktop

    Thanks for the answers everyone.

    I tried using the syntax, but it seems to have a problem with the
    "%HOMEPATH%\Desktop" part. Says that there is a syntaxt error.

    When I try only "%HOMEPATH%" i get "Access denied", although I can open
    this folder through Explorer

    Strange....


  6. Re: Batch file operation copies files to desktop

    On 18 Apr 2005 01:03:57 -0700, jeanjanssens@hotmail.com wrote:

    >Thanks for the answers everyone.


    >I tried using the syntax, but it seems to have a problem with the
    >"%HOMEPATH%\Desktop" part. Says that there is a syntaxt error.


    >When I try only "%HOMEPATH%" i get "Access denied", although I can open
    >this folder through Explorer


    >Strange....


    I just realized that the %HOMEPATH% doesn't specify the drive, so if
    you are running the batch file on a different drive, it won't work
    unless you use the %HOMEDRIVE% variable too. E.g.,

    copy \\fileserv\netdir\file.txt
    "%HOMEDRIVE%%HOMEPATH%\desktop\file.txt

    (all one line, of course; darn word-wrap! There's a space between
    file.txt and "%homedrive too)

    By the way, you can find out what other nifty environmental variables
    have been created by going to the command prompt and typing SET.

    I don't know about the access denied bit, but the syntax error may be
    caused by a missing "quote" around the %HOMEPATH% bit; those spaces in
    "Documents and Settings" are *really* annoying.


  7. Re: Batch file operation copies files to desktop

    Spalls Hurgenson wrote:
    > On 18 Apr 2005 01:03:57 -0700, jeanjanssens@hotmail.com wrote:
    >
    > >Thanks for the answers everyone.

    >
    > >I tried using the syntax, but it seems to have a problem with the
    > >"%HOMEPATH%\Desktop" part. Says that there is a syntaxt error.

    >
    > >When I try only "%HOMEPATH%" i get "Access denied", although I can

    open
    > >this folder through Explorer

    >
    > >Strange....

    >
    > I just realized that the %HOMEPATH% doesn't specify the drive, so if
    > you are running the batch file on a different drive, it won't work
    > unless you use the %HOMEDRIVE% variable too. E.g.,
    >
    > copy \\fileserv\netdir\file.txt
    > "%HOMEDRIVE%%HOMEPATH%\desktop\file.txt
    >
    > (all one line, of course; darn word-wrap! There's a space between
    > file.txt and "%homedrive too)
    >
    > By the way, you can find out what other nifty environmental variables
    > have been created by going to the command prompt and typing SET.
    >
    > I don't know about the access denied bit, but the syntax error may be
    > caused by a missing "quote" around the %HOMEPATH% bit; those spaces

    in
    > "Documents and Settings" are *really* annoying.



    SET (from the command line) shows all the variables availaable. I used
    the following to copy to a users Desktop:

    %USERPROFILE%\Desktop


  8. Re: Batch file operation copies files to desktop

    More followup: below is the sub created using information from another
    posting:

    Private Sub Command201_Click()
    Dim CommandLine As String
    Dim FileSpec As String
    Dim VDesktop As String


    FileSpec = "\\abyss\shared-data\Internal Controls\Control
    Matrix\Stellent Reporting Module.mdb"

    VDesktop = "%USERPROFILE%\Desktop"

    CommandLine = "copy """ & FileSpec & _
    """ """ & VDesktop & """"

    Shell Environ("comspec") & " /c " & CommandLine, vbHide
    Quit
    End Sub

    This copies a file from a network sharefolder (per the FileSpec
    variable), then copies it to the user's desktop. Works great.


+ Reply to Thread