Skip to content

The Batch Scripting Course

A complete, self-paced course on Windows batch scripting (.bat / .cmd files run by cmd.exe). Work through it top to bottom, or jump to the level that matches your experience.

How this course is organized

Folder For you if... Outcome
Beginner You have never written a .bat file Write real scripts: variables, arguments, if, for, file operations, subroutines
Intermediate You can write basic scripts but hit weird bugs Delayed expansion, string surgery, for /F, error handling, menus, scheduling
Advanced You maintain batch scripts and want to do it well Recursion, registry, WMIC/PowerShell interop, findstr regex, hybrid scripts, packaging, debugging

Each lesson is one file and follows the same shape:

  1. What & why – the idea in plain language
  2. Examples – runnable code you should type out yourself
  3. Common mistakes – the traps everyone hits
  4. Exercises – do these; reading is not learning
  5. Recap

Setup (do this first)

You need Windows. Everything in this course ships with the OS — no installs.

cmd /c ver

That prints something like Microsoft Windows [Version 10.0.26100.xxxx]. If you can open a Command Prompt window (press Win, type cmd, Enter), you are ready.

A good editor helps a lot: VS Code (set the file language to "Bat"), or Notepad++. Avoid Windows Notepad for anything non-trivial — it hides line-ending and encoding problems.

.bat vs .cmd

They are the same to you 99% of the time. .cmd is the modern extension and has one small advantage covered in Lesson 1. This course uses .bat in examples because it is what you will see in the wild.

Batch is not PowerShell

cmd.exe batch and PowerShell are different languages. This course is about cmd.exe batch — the language of .bat files, AUTOEXEC.BAT, most CI scripts on Windows, and countless installers. Advanced Lesson 4 covers when to call PowerShell from batch and when to just switch languages.

How to study

  • Type every example. Copy-paste teaches you nothing.
  • Run it in a Command Prompt window, not by double-clicking — a double-clicked script closes its window the instant it finishes or errors, and you never see what happened.
  • Break things on purpose. Change a line, predict the result, run it.
  • Do the exercises before looking at solutions.
  • One lesson per sitting is plenty.

Curriculum at a glance

Beginner

  1. Setup & your first script
  2. echo, comments & script structure
  3. Variables & set
  4. Command-line arguments
  5. Conditionals with if
  6. Loops with for
  7. Files & folders
  8. Redirection & pipes
  9. Subroutines with call & goto
  10. Capstone: file organizer

Intermediate

  1. Delayed expansion
  2. String manipulation
  3. for /F deep dive
  4. Error handling & exit codes
  5. setlocal, endlocal & scope
  6. Arrays & pseudo data structures
  7. Date, time & math
  8. User interaction & menus
  9. Scheduling & running scripts
  10. Capstone: backup utility

Advanced

  1. Recursion & advanced for
  2. Robust argument parsing
  3. Working with the registry
  4. WMIC, where & calling PowerShell
  5. Text processing with findstr
  6. Performance & pitfalls
  7. Hybrid scripts
  8. Packaging & distribution
  9. Debugging techniques
  10. Capstone: deployment automation

License

Use freely for learning and teaching.