Tech Off Thread

12 posts

Old fashioned .BAT files in XP? XCopy help

Back to Forum: Tech Off
  • dentaku

    I know you can still use .bat files in XP but it's not always straightforward for someone like me who doesn't deal with those kinds of things. I know, it's not rocket science but it's not Photoshop either and I know allot more about Photoshop than I know about old fashioned .bat files Smiley

    QUESTION:
    I just want to make a .bat file that will simplify the process of copying a few folders to another folder on a different machine on the network.

    This is for some office workers who don't do backups of their important stuff often enough. A single click solution is what they need but I don't need anything automatic like scheduled backups. I have no way of knowing when any machine will be running or not running so I'd rather have them do it manually.

    ALSO:
    It would be great if I could pass a command to xcopy (I'm assuming xcopy would be used) that would make it compare both the local files and the remote files to see if they've been changed and only update the new ones.
    I know it's possible after reading this document: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/xcopy.mspx

    So, basically it would be
    xcopy c:\ a few folders like My Documents
    \\station3\backups\ (the other computer on the network)
    THEN a bunch of commands like /d

  • Cannot​Resolve​Symbol

    Ummm... I think you answered your own question.

    For each folder you want to back up:

    xcopy /d "c:\source folder" "\\server\destShare"

    For future reference, there is a command line reference in the Windows Help and Support Center.  Look up "Command Line Reference A-Z".

    A .bat file is just a plain text file with each command you want to run on its own line.  You may want to start it with @echo off so that all the commands you run won't be shown in the command prompt window (makes it look less like a batch file).

  • Jorgie

     You need to check out robocopy...

    robocopy /mir  \\machine1\share1\dir1 \\machine2\share2\dir2

    Will mirror one to the other and only sends updated files over the network... (WARNING: /mir and /purge will delete files on the dest. if they do not exist on the source. Use /s /e first to make sure your paths are correct!)

    It is part of the 2003 RK and works great in XP..

    http://www.microsoft.com/downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en


    Jorgie

  • sbc

    xxcopy is good replacement for xcopy (better than Robocopy)

  • dentaku

    OK, I just made 2 folders in the root of C: and tested it out and it seems to work. I'll have to try it over a network next I guess.

    This is what I came up with:
    @echo off
    xcopy /d /i /s /e /y "c:\source" "c:\destination\backup"
    xcopy /d /i /s /e /y "c:\source2" "c:\destination\backup2"

    /d only copies new files
    /i creates new folders in the destination if they don't already exist
    /s copies directories and subdirectories, unless they are empty
    /e copies subfolders
    /y stops it from asking if I want to overwrite

    I'm thinking I don't need both /s AND /e. One or the other should do.

    All I have to do is replace C:\ with \\station3\backup I guess.

    The fun part of this project (other than learning stuff I haven't had to do since the old days of DOS) will be making the .ico file for the .bat so that the workers will have something that looks like an application instead of the standard .bat file icon.

  • billcd

    I've been having trouble use XCOPY with files from a network address.  Sometimes it works, so I'm told, but so far I get "file not found".  I tried:

    XCOPY /d \\machine1\dir1\dir2\dir3\dir4\*.* c:\dirtmp 
    and I get "file not found - *.*

    My alternative is to use Copy, which would be a pain without the /d function!

    Any thoughts?

    XXCopy would be nice but the paperwork to approve the cost is prohibitive.

  • Matthew van Eerde

    dentaku: If you're using xcopy as a backup mechanism, you might consider the /m flag instead of /d (although you should make sure it doesn't interfere with any other backup mechanism in place.)

    billcd: Is it possible the file isn't found because you have the path wrong?  Try mapping a drive to \\machine1\dir1, then cd to \dir2\dir3\dir4 on that drive and type dir to see what files are there.

    If the path contains spaces, you need to wrap the whole path (including *.*) in quotes.

  • billcd

    Thanks, Mathew..

    The path is fine, as I have no problem when I change XCOPY to COPY.  No spaces either.

    Before I can get to the files I had to Logon to machine1.  Then I could see all the files.

    I saw a comment somewhere that talked about a .pif file and a chech box allowing MS-DOS to see Windows files..but I think is was pre-XP, so may not apply.

  • Sven Groot

    billcd wrote:
    The path is fine, as I have no problem when I change XCOPY to COPY.

    That doesn't mean anything since copy is built-in to cmd.exe (it's not a separate executable) so it'll work always regardless of your path whereas xcopy is an exe file in %WINDIR%\System32.

  • billcd

    1. Thanks for the input!  I took Matthew's advice and Sven's hint, and tried mapping the network drive to z: and then XCOPY z:\dir1\dir2\dir3\*.* C:\dir1\dir2\dir3 and this worked.

      So I'm making progress!
      Question is how can I map the network drive in some automated way.  Right now the user can goto start\run and enter \\machine1  This pops up the login screen and then they can see an explorer window.   How can a map this drive to dir1 or dir1\dir2\dir3?  Can I do it from the copyf.bat that I'm writing to do the copying?  I only know how to do it manually.

    Thanks!

  • phreaks

    billcd wrote:
    
    1. Thanks for the input!  I took Matthew's advice and Sven's hint, and tried mapping the network drive to z: and then XCOPY z:\dir1\dir2\dir3\*.* C:\dir1\dir2\dir3 and this worked.

      So I'm making progress!
      Question is how can I map the network drive in some automated way.  Right now the user can goto start\run and enter \\machine1  This pops up the login screen and then they can see an explorer window.   How can a map this drive to dir1 or dir1\dir2\dir3?  Can I do it from the copyf.bat that I'm writing to do the copying?  I only know how to do it manually.

    Thanks!



    net share /?

    H:\>net share /?
    The syntax of this command is:


    NET SHARE
    sharename
              sharename=drive:path [/USERS:number | /UNLIMITED]
                                   [/REMARK:"text"]
                                   [/CACHE:Manual | Documents| Programs | None ]
              sharename [/USERS:number | /UNLIMITED]
                        [/REMARK:"text"]
                        [/CACHE:Manual | Documents | Programs | None]
              {sharename | devicename | drive:path} /DELETE

  • figuerres

    billcd wrote:
    
    1. Thanks for the input!  I took Matthew's advice and Sven's hint, and tried mapping the network drive to z: and then XCOPY z:\dir1\dir2\dir3\*.* C:\dir1\dir2\dir3 and this worked.

      So I'm making progress!
      Question is how can I map the network drive in some automated way.  Right now the user can goto start\run and enter \\machine1  This pops up the login screen and then they can see an explorer window.   How can a map this drive to dir1 or dir1\dir2\dir3?  Can I do it from the copyf.bat that I'm writing to do the copying?  I only know how to do it manually.

    Thanks!



    C:\>Net Use /?

    The syntax of this command is:


    NET USE
    [devicename | *] [\\computername\sharename[\volume] [password | *]]
            [/USER:[domainname\]username]
            [/USER:[dotted domain name\]username]
            [/USER:[username@dotted domain name]
            [/SMARTCARD]
            [/SAVECRED]
            [[/DELETE] | [/PERSISTENT:{YES | NO}]]

    NET USE {devicename | *} [password | *] /HOME

    NET USE [/PERSISTENT:{YES | NO}]

    there are many other Net commands to check out also...

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.