Our new Indie Games subforum is now open for business in G&T. Go and check it out, you might land a code for a free game. If you're developing an indie game and want to post about it, follow these directions. If you don't, he'll break your legs! Hahaha! Seriously though.
Our rules have been updated and given their own forum. Go and look at them! They are nice, and there may be new ones that you didn't know about! Hooray for rules! Hooray for The System! Hooray for Conforming!

Simple batch file for backup?

ThanatosThanatos Registered User regular
edited November 2010 in Help / Advice Forum
Is there a way to write a batch file or something simple that will copy a file from one location to another, overwriting the old file there with no prompting?

I want something like this to do a simple backup of a couple locally-stored files on one of my boss' laptops, because he just lost some stuff and would really appreciate a solution like this, I think.

Thanatos on

Posts

  • DrFrylockDrFrylock Registered User regular
    edited November 2010
    Yes.
    copy /y source destination
    

    will overwrite without prompting. xcopy (which has more options) also supports this, but can copy directories and such. If you want to copy over a network, obviously you'll need to have some way of mounting the remote drive. If the Z: drive isn't in use on the machine, you can do that with something like:
    net use z: \\computername\sharename password /USER:user /PERSISTENT:no
    copy /y C:\Somedirectory\Somefile.ext Z:\Backups
    net use z: /DELETE
    

    If the remote host is UNIX and supports ssh/sftp, you can get rsync or scp for Windows or something to do it.

    You can put anything you want in a batch file, just put it in a text file with extension .bat or .cmd. If you want to suppress the output of the actual commands, put:
    @echo off
    

    as the first line.

    Spoiler:
  • ThanatosThanatos Registered User regular
    edited November 2010
    So, I feel like a retard, because I can't get this to work.

    I've tried it down to the most basic (just the copy C:\directory\file.ext X:\other directory) and it still doesn't do shit.

    I'm directing it to a mapped network drive; that should be okay, right? Or do I have to do something different?

  • urahonkyurahonky Registered User regular
    edited November 2010
    I'm assuming you have read/write privileges on the X:\ drive? Do you get an error? Can you cd to the drive? (eg 'cd X:\')

    Games completed recently: The Witcher, Resident Evil 4: HD Edition, Typing of the Dead: Overkill, Sleeping Dogs, Dishonored.
  • urahonkyurahonky Registered User regular
    edited November 2010
    Seems silly, but also make sure you don't have spaces in the first/second directory. You can put ' around them, and it'll be fine.

    Games completed recently: The Witcher, Resident Evil 4: HD Edition, Typing of the Dead: Overkill, Sleeping Dogs, Dishonored.
  • ThanatosThanatos Registered User regular
    edited November 2010
    urahonky wrote: »
    Seems silly, but also make sure you don't have spaces in the first/second directory. You can put ' around them, and it'll be fine.

    Ah, I did not know that (the directory names have spaces in them, so I was putting spaces in them). Thanks!

  • urahonkyurahonky Registered User regular
    edited November 2010
    Thanatos wrote: »
    urahonky wrote: »
    Seems silly, but also make sure you don't have spaces in the first/second directory. You can put ' around them, and it'll be fine.

    Ah, I did not know that (the directory names have spaces in them, so I was putting spaces in them). Thanks!

    Yeah I hate that about command-line. I normally just put the ' around them even if they don't so I don't have to deal with it.

    Games completed recently: The Witcher, Resident Evil 4: HD Edition, Typing of the Dead: Overkill, Sleeping Dogs, Dishonored.
Sign In or Register to comment.