Tried to make a helpful batch script for something at work and learned some new things I thought I’d write down here so I know where to find it later.
Turn off echoing
Should be known by everyone really, but in case you don’t. Prevents the commands in the batch script and the command prompt to show up while the script is running. Beginning a line with @ does this for a single command.
REM Will still appear as a command if you haven't disabled echoing
Labels and goto
Trivial, but I keep forgetting about this since I never use it in other programming.
REM Will be skipped
Set title of command prompt
Check command line arguments
if not exist %~1 (echo %~1 does not exist && goto end)
if ERRORLEVEL 2 (
echo Ok, I'll do it
Run other batch scripts
If you don’t use the call command, the other script will actually take over and your script will end.
Do the same thing with various subjects
) do (