Intermediate¶
You can write basic scripts but you keep hitting bugs that make no sense — a variable that won't update inside a loop, a comparison that's always false, a script that "works" but leaves junk in your environment. This level explains why, and gives you the patterns that make batch scripts reliable.
Lessons¶
| # | Lesson | You'll learn |
|---|---|---|
| 1 | Delayed expansion | setlocal enabledelayedexpansion, !var!, the loop-variable bug |
| 2 | String manipulation | substrings %v:~n,m%, substitution %v:a=b%, length, case |
| 3 | for /F deep dive |
tokens, delims, skip, eol, usebackq; parsing command output |
| 4 | Error handling & exit codes | errorlevel vs %errorlevel%, &&, ||, exit /b n |
| 5 | setlocal, endlocal & scope |
environment isolation, returning a value past endlocal |
| 6 | Arrays & pseudo data structures | set "a[0]=...", counts, iteration, associative lookups |
| 7 | Date, time & math | %date%/%time% locale traps, set /a operators & bases |
| 8 | User interaction & menus | choice, set /p, a robust menu loop |
| 9 | Scheduling & running scripts | schtasks, start, elevation, runas, working directory |
| 10 | Capstone: backup utility | logging, rotation, error handling, exit codes |
How to work through it¶
- Every lesson here fixes a bug you have already hit or are about to. Type the "broken" examples too — seeing the failure is the point.
- Keep Lesson 1 (delayed expansion) close; it explains half of all batch weirdness.
When you're done¶
Go to Advanced.