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

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: May 21, 2019

Author

Comments

Write a Reply or Comment