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
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.

problem with copying files in batch file....

  • 14-12-2012 03:55PM
    #1
    Registered Users, Registered Users 2 Posts: 1,401
    ✭✭✭


    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?


Welcome!

It looks like you're new here. Sign in or register to get started.

Comments

  • Registered Users, Registered Users 2 Posts: 976 unseenfootage
    ✭✭✭


    All you need is this line :

    xcopy /s c:\source d:\target


  • Registered Users, Registered Users 2 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, Paid Member Posts: 11,196 Fysh
    Mod ✭✭✭✭


    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: 95,751 Capt'n Midnight
    Mod ✭✭✭✭


    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, Paid Member Posts: 11,196 Fysh
    Mod ✭✭✭✭


    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: 95,751 Capt'n Midnight
    Mod ✭✭✭✭


    mozy backup free version also makes backups to local drives too


Welcome!

It looks like you're new here. Sign in or register to get started.
Advertisement