Tutorial
Introduction
Thanks for reading this tutorial, we will explain the basics of DOS Batch File Scripting to you.
What is a Batch file?
Batch file’s where used very much in the Operating System that’s called DOS.
Why would we use Batch files while its more than 15 years old?
With a batch file you can sent some code “under the motor hood” in Windows. That way its faster than you use the Explorer and you can start program’s after each other with 1 click.
Cool ! But for what kind of thing can we use it?
For example a back-up script. Start some programs and even some more advanced thing like start you antivirus scanner, auto update it and auto scan and fix the problems. That are just 2 examples!
Cool ! Let’s start?
Alright, let’s start. In this lesson you will learn how a Batch file works and how to create a Batch file.
Step 1 – Information.
A batch file can’t be started from anywhere. Its only possible in Microsoft Windows system, linux and MacOS will use some other languages.
Step 2 – Create a batch file and show Hello World
Alright, we’re going to start with your first batch file ! Create a directory where you will save your batch files. I will use C:Batch. I will use this path for all tutorials that are written !
Alright, when you’ve created the directory we’re going to create the first file. Create a Notepad file and call it helloworld. Open the file and save it as helloworld.bat.
When the file is created, we’re going to put the first text in it. Where first are going to place some comments, this is the most important thing you must use while your programming ! This way you can see what that part of the script is doing.
Aright lets place the comment, for a comment you need to use the : sign. All text after the : won’t be started when you’ve run the script. So lets place the following text “:This is my first batch file”.
After that is done, we’re going to place some text in it, so if you run the batch file you can see that its doing something. First we’re going to put cls under your comment. Cls means “clear screen” so you can’t see old comments in your DOS-Box.
Now we have the following batch file:
Code:
:This is my first batch file
Cls
Now we’re going to show some text on the screen. Under CLS we are going to put “echo hello world!”. This will put “hello world!” on the screen. But its so fast you can’t see it. So we are going to add a “Pause” so it will be stopped so you can see what’s on the screen. So now we have the following code:
Code:
:This is my first batch file
cls
echo test
pause
And now its time to run the script. Save the file, and click twice on helloworld.bat. You will see the following results on your screen:
Code:
C:Batch>echo test
test
C:Batch>pause
Druk op een toets om door te gaan. . .
(I have a Dutch version of windows. So the “druk op een toets..” will be in english “press a button…”
So you’ve created your First batch file ! Next time we’re going to make something useful. A back-Up script !
Kind regards,
Nick
Comments
Remco - 2009-02-08
lol this is very cool
I can't wait untill the back-up script , I wonder what it will be like lol.
One question:
Is it possible to not show the: echo hello world! in the prompt but still execute it ?
Remco.
I can't wait untill the back-up script , I wonder what it will be like lol.
One question:
Is it possible to not show the: echo hello world! in the prompt but still execute it ?
Remco.
Nick - 2009-02-09
Yes that possible,
Place @echo off above the echo command and you won't see it again.
Nick
Place @echo off above the echo command and you won't see it again.
Nick
You have to be logged in to write a comment.



