Friday, January 22, 2010

Batch File Programming:

BAT FILE Programming:

Bat file programming is a way of executing set of command by a single click or enters.
Batch file programming is a windows version of UNIX shell programming.
Command.com is file in windows that handles all DOS commands.
Copy, dir, md etc they are built in command called internal commands.
DOS has also External Commands such as BACKUP, FORMAT, UNDELETE etc
Then why need BATCH file programming..???
For executing set of commands you not need to remember commands in batch file, you just double click on *.bat extension file and then it perform an appropriate task.
For writing batch file program you can use NOTEPAD and EDIT [dos editor] editor both are Easy to write Batch File program.
After writing code you have to save file with *.bat extension.
After saving file you can execute via double click or open DOS prompt and type your batch file name, like
C:/>mybatch.bat

ECHO This Batch File deletes all unwanted Temporary files from your system
ECHO Now we go to the Windows¥temp directory.
cd windows¥temp
ECHO Deleting unwanted temporary files....
del *.tmp
ECHO Your System Temporary files now Clean

Echo is use to print the message.

Save this file with name mymove.bat, it will be delete your system’s temporary files.

echo off
mkdir %1
echo **the newly created directoryis %1**
move %2 %1
echo **the file is moved to directory%1**
echo on

This batch file code creates a new directory and copy a file in this directory.


Note: file.txt must be inside the present working directory.
Enjoy the Batch Programing........