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>&1 | Create folder if one does not exist. Don’t display an message. |
CALL script02.cmd 1>NUL 2>&1 | Call “script02.cmd” |
DEL *.TXT 1>NUL 2>&1 | Delete all txt files. |
TYPE ..\folder1\*.sql > file.sql | Combine multiple files into one file. |
XCOPY /s /y ..\folder1\*.sql C:\folder2 | Copy specific files to a folder. |
Comments