Batch file tutorial-2
Advance
In Tutorial-1(beginner), I have covered four topics ie "echo,msg,pause and cls"...Here, I will explain "rem,start,set,goto and if".
start and rem:
Create a New Folder!
Name it Test
Put any Picture inside the folder and name it testpicture
Now, Open up Notepad and type
Code:
@echo off
echo Testing start and rem
rem title Test
start testpic.jpg (or any other extension)
pause
Save it as test4.bat
Launch it...and it will show...
Code:
Testing start and rem
Press Any Key To Continue
(and the picture will launch)
So start will Launch any file...
and rem is a Remark(it won't Show in the .bat file when Running)
goto, set and if:
Now, some more Commands are "goto", "set", and "if"
Type this in Notepad...
Code:
@echo off
echo This is a test
echo If you want to do math type 1 and press enter
echo If you want to see a picture type 2 and press enter
set /p option=
if '%option%'=='1' goto :math
if '%option%'=='2' start testpic.jpg (or any extension)
:math
echo 2+2
pause
Save it!
This will show...
Code:
This is a test
If you want to do math type 1 and press enter
if you want to see a picture type 2 and press enter
(here you can type 1 or 2 and press enter)
(if you press 2 and Enter the picture will load)
(if you press 1 and enter this will show up):
2+2
Press any key to continue...
goto:
So goto will go to a Label or a Part of the file
when you put :math
A New Label will be named Math and when you put goto :math
The Batch will go to :math
set:
The set option will set something
...Here it's going to set :choice
set is, in some cases followed by if
So if I type 1...in this example...
The "choice" will be 1...and it will go to :math because we put
if '%choice%'=='1' goto :math
So if we put 1, the choice will be 1 therefore it will go to :math
Simple right?
Anyway those are the Basics...
In Tutorial-1(beginner), I have covered four topics ie "echo,msg,pause and cls"...Here, I will explain "rem,start,set,goto and if".
start and rem:
Create a New Folder!
Name it Test
Put any Picture inside the folder and name it testpicture
Now, Open up Notepad and type
Code:
@echo off
echo Testing start and rem
rem title Test
start testpic.jpg (or any other extension)
pause
Launch it...and it will show...
Code:
Testing start and rem
Press Any Key To Continue
(and the picture will launch)
and rem is a Remark(it won't Show in the .bat file when Running)
goto, set and if:
Now, some more Commands are "goto", "set", and "if"
Type this in Notepad...
Code:
@echo off
echo This is a test
echo If you want to do math type 1 and press enter
echo If you want to see a picture type 2 and press enter
set /p option=
if '%option%'=='1' goto :math
if '%option%'=='2' start testpic.jpg (or any extension)
:math
echo 2+2
pause
This will show...
Code:
This is a test
If you want to do math type 1 and press enter
if you want to see a picture type 2 and press enter
(here you can type 1 or 2 and press enter)
(if you press 2 and Enter the picture will load)
(if you press 1 and enter this will show up):
2+2
Press any key to continue...
So goto will go to a Label or a Part of the file
when you put :math
A New Label will be named Math and when you put goto :math
The Batch will go to :math
set:
The set option will set something

set is, in some cases followed by if
So if I type 1...in this example...
The "choice" will be 1...and it will go to :math because we put
if '%choice%'=='1' goto :math
So if we put 1, the choice will be 1 therefore it will go to :math
Simple right?

Anyway those are the Basics...
Leave a Comment