Friday, July 29, 2011

Learn to make Batch Files!!!!!!!

Making Batch Files


A batch file is a normal text file, no programming involved. You type DOS commands into a text file, each one on a separate line. Then, you give the text file a .bat extension instead of a .txt extension. Now, when you double click the batch file(In Windows Explorer) or type its name at the DOS prompt, it will execute the commands.

First, we need to know some DOS commands. The main DOS commands we will use are copy, move, del, cls, and echo. 
The COPY command has this syntax:
          
copy [source] [destination]

In DOS help, the syntax is more complicated, but we don't need the advanced features for our batch files. 

The COPY command, obviously copies a file. For example, say I wanted to copy a:\readme.txt to a:\windows\help.txt. (By the way, this will also rename the file.) I would type this:

copy a:\readme.txt a:\windows\help.txt

The MOVE command is exactly the same, except it MOVEs the file, and COPY copies the file.

The del command is very simple. It erases a file. It follows this syntax:

del [filename]
 For example, if you wanted to delete a file called a:\happy.txt you would type this:

del a:\happy.txt

The CLS command clears the screen. This is the syntax:
cls
PAUSE is a command that stops the program and prompts you to "Press any key to continue." The syntax is:
pause

ECHO is a DOS command that shows the stuff you type. In a batch program, the @ symbol means not to echo a line. So, typing ECHO OFF prevents the user from watching the batch program execute. And, to keep from echoing the ECHO OFF command, type the @ symbol in front of it. Put it together and you get:

@echo off

All good batch programs start with the @ECHO OFF command followed by CLS. Important!: If you use the @ECHO OFF command in your batch program, be sure to put ECHO ON at the end of the batch program or the user will think their computer is messed up. The ECHO ON command is like this:
echo on


Now for the batch file! First, if you're using Windows, open a DOS prompt. To make a batch program to load a program called myname.bat, type this:

edit myname.bat

Then type:
@echo off
cls
echo Hi, my name is %1
pause

echo This is the contents of this batch file:

pause

type myname.bat

Then save it in a file called myname.bat. The "%1" allows you to add data to your batch file from the command line. Whatever you type after the batch filename at the dos prompt will replace the %1.

At DOS prompt, type
myname Arien
( you can use your name here) and your program will start!



ENJOY!!!!!!!!!

0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...

like it on facebook

Hey frens leave some feedbacks Here!!!!!

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites