Wednesday, January 7, 2009

How to create a simple batch file to backup files or folders

Creating a simple batch file to backup files or folders is a cool way to move, copy, and backup any file you like.

A batch file is a text file saved as a .bat extension and when doubled clicked on it will execute the dos commands contained in that file.

In this article I will be using the xcopy command and the robocopy command to create a batch file to copy a file or folder. If you have Windows XP you will use xcopy for your batch file and if you have Windows Vista you can use the new command, robocopy.

First we need to create a batch file:

  1. Open Notepad by going to the start menu>all programs>accessoires>then choose Notepad.

  2. Type your commands into the notepad file.

  3. Then go to the file menu at the top and choose Save As.

  4. Now save the file as Yourfilename.bat

Some examples on what to write in a batch file to copy or backup files.

xcopy "C:\Documents and Settings\Your username\My Documents\My Pictures" "H:\backup of pictures" /e /y

This command will backup my pictures on C: drive and paste it to H: drive in a folder called backup of pictures. If you put the destination as just H: than all the files will be all over the place. You must specify a folder. I usually make a new folder first. Of course you can also get the batch file to make the new folder for you but this is another article altogether.

/e means to copy all directories and sub directories

/y means to copy with prompting to overwrite the already exsisting files

See this article on How to use xcopy dos command and switches in batch file

No comments:

Post a Comment

Spam and advertising will be removed. One link to a website is allowed.