Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
11Activity
0 of .
Results for:
No results containing your search query
P. 1
Batch File ABCs

Batch File ABCs

Ratings:

4.67

(3)
|Views: 585 |Likes:
Published by Ganesh Babu
ABCs of batch file
ABCs of batch file

More info:

Published by: Ganesh Babu on Oct 14, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as RTF, PDF, TXT or read online from Scribd
See more
See less

03/09/2012

pdf

text

original

 
Batch file ABCs
-From www.Computerhope.com
Batch files allow MS-DOS and Microsoft Windows users to create a lists of commands torun in sequence once the batch file has beenexecuted. For example, a batch file could beused to run frequently run commands, deleting a series of files, moving files, etc. Asimple batch file does not require any special programming skills and can be done byusers who have a basic understanding of MS-DOS commands.  A good example of a batch file for someone who is more familiar with Windows or theMacOS is to think of a batch file as ashortcutin Windows or an icon on the MacOS.Much like a shortcut, batch files could be used to run one or more commands and/or  programs through thecommand line.Another example of a very well known batch file is the autoexec.bat, which is a simple  boot file loaded each time the computer is loaded on MS-DOS and early Windowscomputers. This batch file contained all the necessary commands and programs used torun MS-DOS and Windows each time the computer booted.
Creating a batch file
To create a basic batch file in MS-DOS, follow the below steps that give you an exampleof how to create a basic batch file.Open an MS-DOS command window or get to MS-DOS. Additional informationabout doing this can be found ondocument CHDOS.  At the MS-DOS prompt, type:
edit test.bat
and press enter.If typed properly, you should now be in a blue screen. Within the screen, type: pausedir c:\windowsdir c:\windows\systemOnce the above three lines have been typed in, click File and choose exit; when prompted to save, click "Yes." Users who do not have a mouse cursor canaccomplish this same task by pressing ALT+F to access the file menu, then pressing "X" to exit, and pressing enter to save changes.
 
Once you are back at the MS-DOS prompt, type:
test
and press enter. This willexecute the test.bat file and begin running the file. Because the first line is pause,you will first be prompted to press a key. Once you press a key the batch file willrun line-by-line; in this case, listing the files in the windows and windows\systemdirectories.If you wish to add more lines to this batch file you would simply type "edit test.bat" toedit the file again.Additional information about the MS-DOSedit commandcan be found on our editcommand page. Some versions of MS-DOS and bootable diskettes may not have the editcommand; if this is the case, you would either need to obtain the edit.com file to accessthis file or use thecopy con command.
Microsoft Windows and other users
 A Windows user can still use the above MS-DOS steps if they wish to create a batch file.If, however, you're more comfortable using Microsoft Windows or your operatingsystem, you can use any text editor, such as Notepador  Wordpad,to create your batch files, as long as thefile extensionends with .bat. In the below example we use theWindows notepad to create a batch file.Click Start Click RunType:
notepad
and press enter.Once notepad is open, type the below lines in the file or copy and  paste the below lines into notepad.@echo off echo Hello this is a test batch file pausedir c:\windowsClick File and click Save; browse to where you want to save the file. For the filename, type "test.bat", and if your version of Windows has a "Save as type" option,choose "All files", otherwise it will save as a text file. Once all of this has beendone click the Save button and exit notepad. Now, to run the batch file, simply double-click or run the file like any other program.Once the batch file has completed running it will close the window automatically.
Batch commands
Just like all MS-DOS commands, all batch file commands are notcase sensitive.However, in the below listing we have listed all commands in all caps to help youidentify what is a command and what is not.
 
@
Does not echo back the text after the at symbol. This is most commonly used as
@ECHO OFF
to prevent any of the commands in the batch file from beingdisplayed, just the information needed.
%1
The percent followed by a numeric value, beginning with one, allows users toadd variables within a batch file. The below line is an example of what can beused in a batch file.
ECHO Hello %1
 When the above one-line batch file is created, add your name after the batch file. For example, typing myname (being the name of the bat file) and then your name:
myname bob
 would output:Hello bob
Note:
This can be extended to %2, %3, and so on.
:LABEL
By adding a colon in front of a word, such as
LABEL
, you create acategory, more commonly known as a label. This allows you to skip to certain sections of a batch file such as the end of the batch file. Also see
GOTO
.
CALL
This is used to run another batch file within a batch file. When the batch file that is called is completed, the remainder of the original batch file iscompleted. Note if the batch file does not exist it will give an error message.
CHOICE
See running different programsfor an example of how to use this command.
Additional information and the syntax of this command in each version of Windowsand MS-DOS can be found on our CHOICE command page.
CLS
Just like the DOS command would clear your screen.
Additional information and the syntax of this command in each version of Windowsand MS-DOS can be found on our CLS command page.
ECHO
Will echo a message in the batch file. Such as
ECHO Hello World
will print
 Hello World 
on the screen when executed. However, without
@ECHO OFF
at the beginning of the batch file you'll also get "ECHO Hello World" and "HelloWorld." Finally, if you'd just like to create a blank line, type
ECHO.
adding the period at the end creates an empty line.
EXIT
Exits out of the DOS window if the batch file is running fromWindows.

Activity (11)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
nathan_pfelix liked this
nathan_pfelix liked this
millionmade03 liked this
pendoo liked this
sanjoy007 liked this
sanjoy007 liked this
Zato Ichi liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->