Batch Scripting
Batch Scripting
Comments
Rem Remarsks
Example:
@echo off
Rem This program just displays Hello World
set message=Hello World
echo %message%
Alternatively
:: Remarks
Example:
@echo off
:: This program just displays Hello World
set message = Hello World
echo %message%
Example:
if exists filename.txt(
echo deleting filename.txt
del filename.txt
)else(
echo This file was not found.
)
Comparison Operators
EQU:Equal
NEQ:Not Equal
LSS: Less than <
LEQ: Less than or Equal <=
GTR: Greater than >
GEQ: Greater than or equal >=
NOT: (executes the command if false)
Parameters
Values than can be passed into our script when we run it
These can be accessed similar to variables however they have no trailing% symbol
Parameters can be accessed from %1-%9 program param1 parama2 param3 etc
Looping
FOR /L %%G IN (start, step, end) DO command
eg FOR /L %%G IN (1,1,10) DO %%G
Functions
Now that we know how to call functions, let's look at how to construct them
Functions are slightly faked in batch scripting, if you have ever worked in other
programming
languages, you will be aware that functions can return results, have their own
local variables
and can have parameters passed in
:FunctionsUseLabels