Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

problem with copying files in batch file....

Options
  • 14-12-2012 3:55pm
    #1
    Registered Users Posts: 1,305 ✭✭✭


    I want to create a batch file that will allow me to copy from a local hard drive (f:\data) to a local usb hard drive (d:data) that i have attached to my PC

    here is the syntax of the batch file....

    "
    cmd

    f:

    cd data

    xcopy *.* /s /d /Y d:\data"


    Howver when i run this batchfile it just opens the command prompt...
    it wont browse to the f drive which is the second line of the batch file etc..
    what am i doing wrong?


Comments

  • Registered Users Posts: 976 ✭✭✭unseenfootage


    All you need is this line :

    xcopy /s c:\source d:\target


  • Registered Users Posts: 1,731 ✭✭✭GreenWolfe


    If you want to suppress the prompt, add "@echo off" (without the quotes) to the top of the batch file.


  • Moderators, Arts Moderators, Regional Abroad Moderators Posts: 11,022 Mod ✭✭✭✭Fysh


    You don't need the "cmd" at the start and I think your syntax is wrong. Unseenfootage's post gives you the basic command you need, but the Microsoft documentation page for the xcopy command (see here) has the following as an example of an xcopy command that uses if switches to handle error codes:
    @echo off 
    rem COPYIT.BAT transfers all files in all subdirectories of
    rem the source drive or directory (%1) to the destination rem drive or directory (%2) 
    
    xcopy %1 %2 /s /e 
    
    if errorlevel 4 goto lowmemory 
    if errorlevel 2 goto abort 
    if errorlevel 0 goto exit 
    
    :lowmemory 
    echo Insufficient memory to copy files or 
    echo invalid drive or command-line syntax. 
    goto exit 
    
    :abort 
    echo You pressed CTRL+C to end the copy operation. 
    goto exit 
    
    :exit
    


  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 90,889 Mod ✭✭✭✭Capt'n Midnight


    TBH have a look at robocopy instead

    xcopy just isn't up to copying large numbers of files , fine for a small folder


  • Moderators, Arts Moderators, Regional Abroad Moderators Posts: 11,022 Mod ✭✭✭✭Fysh


    Or you could script up synctoy and invoke the script via task scheduler - see here.


  • Advertisement
  • Closed Accounts Posts: 414 ✭✭Bosh


    This is the syntax I use to run a a backup every time the PC shuts down: (one line of it obviously :p)

    XCOPY "C:\Users\Office\Desktop\*.*" "K:\Backup\Admin\Desktop" /d/s/e/y

    Yours would be along the lines of:

    XCOPY "F:\Data\*.*" "D:\Data" /d/s/e/y

    The switches are as explained in the link in Fysh's post.

    HTH


  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 90,889 Mod ✭✭✭✭Capt'n Midnight


    mozy backup free version also makes backups to local drives too


Advertisement