Notebook Batchfiles for Windows

Alex van Buitenen

This is not a Batchfile tutorial or Quick Reference.
It is just my personal notebook for batchfiles.

IF
SET
FOR

IF

Check whether file exists.

if not exist <filename> goto :error

:error

Check whether parameters are filled.

set param1=%1
set param2=%2
set param3=%3
set param4=%4
REM controleer parameter-aantal
:C1
IF "%1"=="" GOTO Error1
IF "%2"=="" GOTO Error1
IF "%3"=="" GOTO Error1
IF "%4"=="" GOTO Error1
GOTO C2
:Error1
@ECHO Het aantal opgegeven parameters klopt niet.
@ECHO Aanroep moet zijn:
@ECHO call <filename>l.bat <parameter1> <parameter2> <parameter3> <parameter4>

GOTO END
 

SET

(type SET /? to see help for this command on your Windows version.
 Window help-file (opened by pressing F1 on desktop) does not always show all parameters for this command on different Windows versions)

SET choice=
SET /p choice=Wilt u doorgaan? [J of N]

IF NOT '%choice%'=='' SET choice=%choice:~0,1%
IF '%choice%'=='J' GOTO START
IF '%choice%'=='j' GOTO START
IF '%choice%'=='N' GOTO CANCEL
IF '%choice%'=='n' GOTO CANCEL

:START

:CANCEL

FOR

Example: execute all test*.bat files

calling from batchfile: 
for %%A in (test*.bat) do %%A

calling from command prompt:
for %A in (test*.bat) do %A

Use %variable to carry out for from the command prompt. Use %%variable to carry out the for command within a batch file.
Bron: Windows Technet. zoek op "Command-line reference A-Z‎".