Wednesday, March 10, 2010

Creating a batch file

A batch file is something with the extension of ".bat" or ".cmd".  This file can be edited through Notepad to do multiple tasks like copying multiple files.  It can practically be used for anything, but I will show a sample batch file to copy multiple files from different directories.

Suppose when you make a picture CD and you don't want to use the Windows Explorer every time you put a new CD into your computer.  If there are no folders this works perfect.

Batch File:

Every line is like going into Microsoft DOS or the Command Prompt window and typing the lines.
The first line goes to the C Drive.
The second line makes a new directory named "New Pictures".  MD is the same as make directory.  If you have a space in a name, you have to surround the name with quotes.  If it was NewPictures, then the quotes would not be needed. 
The third line goes to the D Drive (or whichever drive is the CD drive)
The fourth line copies everything from the root of the CD drive over to the newly created directory, "New Pictures".  The asterisk is a wild character which means use everything.
The fifth line doesn't have to be there.  PAUSE means to wait for user input on the screen so you can see what is happening with the batch file.  If you did not have the PAUSE in there, then the Command Prompt window would go away right after the last line completed.

A lot more can be done with this file and you can do any DOS command that you know within the batch file.  The options are limitless for a batch file.

No comments:

Post a Comment