Hiii Friends :
This is Rakesh.J
Juz wanna tel u al about
The Basics Of Batch File Programming.
'Coz I know only the Basics... :-)
1.INTRODUCTION :
Anywayz... Now, What is a Batch File ?
Batch file is just a series of commands
written in Notepad or any text editor
with an extension " bat ".
We can give any number of commands
in the batch file programming...
except the syntax must be correct.
You might be thinking that
what these commands might be!
Dont worry by looking at the words
like " syntax " and " commands "...
These are not the Big Structural Commands
and Syntaxes of a
" C " program or " Java " or
what ever be the other languages one!
These are just the commands of
a normal command prompt.
You can find all these commands
in the command prompt by just..
Opening the command prompt and
tying " help " under...
Simple??
Thats the Beauty of a Batch File Programming...
You can also edit ant batch file,
By just right clicking it and clicking " edit "
It gives a Great Programing Xperience
with a just few number of steps...
Lets start making a batch file... :-)
2.MAKING A BATCH FILE:
To make a batch file,you just open a note pad
enter the commands,
and when saving it,give the extension as ".bat".
that is,"yourfilename.bat" instead of
"yourfilename.txt".
I would give you one example..
Creating A Batch File By Batch File Programming :
Go to start menu
Open "run" type "notepad"
and ur notepad is opened.
Simply type "logoff.exe" in your notepad
Close it and save it, with the extension of "bat"
To be clear, the text file must be
"logoff.bat" or any other "yourwish.bat"
As simple as eating a banana....
(Banana is one of my favorite fruit :-)
Yes, you have created a batch file,
what now?
How to use it?
Just go to your batch file and double click on it...
You would see your system logging off!!
Isn't cool??
If yes learn more....
Create a batch file to copy a file from one folder to another
For answer verification comment me with ur email id...
For assistance and more information on
batch file programming mail me at...
" http://innovationdelightes@gmail.com "
3.WORKING :
Yeah... Fine....
I think now you are able to make
small batch file programs...not that too small:-)
But,have u thought how the stuff works???
Well,I will tell you...
The moment you double-click on any batch file,
the command prompt gets initialized and
The commands which you have given,
gets executed line by line...
The command prompt first executes
the command of first line
and then goes to second line.. and so on...
If the syntax of the commands given are correct,
The file would give you the appropriate result...
But if it gets under the wrong syntaxed commands,
like we normally do!;
The prompt gets terminated and gives you the result..
Upto the correctly syntaxed commands...
Got it???
Thats how a batch file works...
Why staring at that thing so seriouisly??
Go now,and create a batch file to shutdown your PC...
For help,type "help shutdown"
in your command prompt...
Be aware of the options of shutdown...
It wont work without the options...!
Mail Me To Know More about Batch Filing..
innovationdelightes@gmail.com
4.BATCH FILEing IN DETAIL :
Are you satisfied with it?? No?? Well, me either!
Okay now Im going to tell you the
whole batch file(ing) in detail....
Lets start with an example... as I always do...
Okay, I will give you some useful example.....
I think you all be knowing where
the temp files are stored
and to delete them timely...
Lets start now...
Open your notepad....
Type "cd.." - to change the current directory..
Then, "c:" - to get in to c drive..
The command:" del /Q c:\windows\temp\*.* "
- to delete all files(not folders) from temp directory of windows
Immediately," del /Q c:\windows2\prefetch\*.* "
- to delete all files from prefetch
Finally,"del /Q "c:\documents and settings\"your user name"\
local settings\temp\*.*" - to delete from %temp%
exit - to exit...
So, your note pad should look like this...
cd..
c:
del /Q c:\windows2\temp\*.*
del /Q c:\windows2\prefetch\*.*
del /Q "c:\Documents and Settings\your user name\
localsettings\temp\*.*"
exit
( Of course, Not in Red Color :-) )
And finally save the file with extension "bat"
after closing it... Hurray!! Your batch file is created...
Now double click on it and see the magic...
Check all temporary files if there in your system...
No Files??? That was successfully done...
Those are the Basic Temp folders...
To Know all the temp folder and
wanna delete them, Watch the video down there... :-p
Did you noticed 4 things here?? Did you???
1).The command "del"...
2).The option "/Q"...
3).The " " marks for only the 5th line command
4).Last, the " *.* " ..
1) " del " is the command to delete files...
2).The option "/Q" is given to
delete these files forcibily...
If this option is not given,
the prompt asks for confirmation (y/n) to delete the files..
3).The " " marks are given only to the
5th command. This is because,in the adress,
(Documents and Settings\username\local settings)
contains spaces...
So our Brother prompt does not considers
them as spaces if the marks " " are not given
Hence it takes as
(DocumentsandSettings\username\localsettings\) and
searches for the folder...
(Ofcourse, it doesnot finds them either!)
So, the cotation marks " " are given to them...
Hence, by giving the marks " " the prompt considers
it as a whole string and executes the command.
4).The " *.* " notation! It indicates
the prompt which files to delete.
If you give the command " del /Q c:\a\*.bat ",
it 'Q'uietly deletes all bat files
from the folder c:\a (if present any!)
If you give the command
copy c: \ a \ any . * d : \ b,
It would copy all files with name "any" having
any extension from c:\a to d:\b
And thats how it works...
Finished learning???
Go now and make a batch file to copy
all files of extension ".exe" from c:\windows
and paste them to any folder
You got it???
Really did you get it by yourself???
No??? Mail Me and I wud send u the answer :-)