.bat file code example
Example 1: bat file
//Save it as start_dev.bat
@ECHO off
cd "C:\xampp"
start xampp-control.exe
cd "C:\Users\..."
start cmd /k "code . && ng s -o"
cd "C:\Users\..."
start cmd /k "code-insiders . && php artisan serve"
Example 2: bat stop if call command fails
The ERRORLEVEL environment variable holds the latest return value:
IF %ERRORLEVEL% NEQ 0 (
echo "Previous command execution failed."
exit %ERRORLEVEL%
)
Example 3: batch write file
REM
REM
echo This is the text you want in the actual file > NewFile.txt
REM
REM
Example 4: what is a windows batch file
@ECHO OFF
ECHO Congratulations! Your first batch file executed successfully.
PAUSE
Example 5: batch file extension
@echo off
setlocal
set file=C:\Users\l72rugschiri\Desktop\fs.cfg
for %%i IN ("%file%") do (
echo filedrive=%%~di
echo filepath=%%~pi
echo filename=%%~ni
echo fileextension=%%~xi
)