In Windows, the batch file is a file that stores commands in a serial order. Command line interpreter takes the file as an input and executes in the same order. A batch file is simply a text file saved with the .bat or .cmd file extension. It can be written using Notepad or any other text editor.

ECHO OFF
ECHO Hello World
PAUSE
ECHO OFF
CLS

SET /P userInput=This action will do something, do you wish to continue? (Y/N): 

IF "%userInput%"=="Y" GOTO STEP1
IF "%userInput%"=="y" GOTO STEP1

GOTO END

:STEP1
ECHO .
ECHO Step 1
ECHO.

ECHO.
ECHO -------------------------------------------------------------------------------
ECHO Something
ECHO -------------------------------------------------------------------------------

ECHO Do Something

ECHO.
ECHO -------------------------------------------------------------------------------
ECHO.

GOTO SUCCESS

:ERROR
ECHO -------------------------------------------------------------------------------
ECHO !!!!!                ERROR OCCURRED                                       !!!!!
ECHO -------------------------------------------------------------------------------

:SUCCESS
ECHO Successfully
PAUSE
GOTO END

:END
EXIT
@ECHO OFF

REM Check First Parameter
IF "%1" EQU "Quiet" SET RealName=John Doe
IF "%1" EQU "Quiet" GOTO BP01

SET /P RealName=What is your name (Default John Doe)?: 

IF "%RealName%"=="" SET RealName=John Doe

ECHO  %RealName%

SET /P userInput=Do you wish to continue? (Y/N): 

IF "%userInput%"=="Y" GOTO BP01
IF "%userInput%"=="y" GOTO BP01

GOTO BP02

:BP01
ECHO.
ECHO Break Point 1
ECHO.
ECHO %RealName%
ECHO.

:BP02
ECHO.
ECHO Break Point 2
ECHO.
PAUSE

Comment Commands

MKDIR D:\TestFolder 1>NUL 2>&1Create folder if one does not exist. Don’t display an message.
CALL script02.cmd 1>NUL 2>&1Call “script02.cmd”
DEL *.TXT 1>NUL 2>&1Delete all txt files.
TYPE ..\folder1\*.sql > file.sqlCombine multiple files into one file.
XCOPY /s /y ..\folder1\*.sql C:\folder2Copy specific files to a folder.
Last modified: July 28, 2020

Author

Comments

Write a Reply or Comment