Interactive Batch Course with built-in Reference
The versatile MS-DOS/MSDOS Batch Language automates routine tasks with Batch files (lists of Batch commands). Learn how to write Batch files with this free, interactive Course and built-in Batch Reference. You need no prior knowledge of Batch files: you're guided through each step on screen in your Web Browser – no need for printouts.
What's new or quick if you're in a rush?
The full Batch Course or just a
In our full Course of 21 interactive Lessons, you build a menu-driven Batch file project for backup, and learn a wide range of Batch file skills. Try the full Batch File Course, or a
click for details. Use a link below: the Lesson loads in your Browser.
Lesson Index and Course Syllabus
Get introduced first
This fully-interactive Course probably isn't like anything else you've met on the Web. That's why there's an interactive . Think of it as Lesson Zero. You will:
- Learn to use the interactive Exercises on which the entire Course is based
- Create the working folder used for all the Batch file work that follows
- Create and configure the BatchWindow (a DVM, or DOS box) for Batch work
- Configure and practise with the multiple window layout used in the Lessons
- Learn to use our clickable, on-screen Course Reference for Batch file terms
The Lesson pages are designed so that you can
(click for details) .
The Course is written for Windows 95/98/ME. users who want to try the Course need (click
for a summary).
Note Our clickable on-screen Course Reference loads with every Lesson and grows in detail as you progress. We don't load it with this Lesson Index and Syllabus page, which gives only an overview. So Batch terms/commands on this Index page aren't clickable.
Backup Batch files are powerful tools. Always backup. Read our .
Two ways to study:
1 Graduated Lessons
In the you learnt to create a custom MS-DOS window that is ideal for Batch file work. To follow an interactive, thorough, and carefully graduated set of Lessons in which you learn to write your own Batch files, continue with the Lesson 1 Syllabus now.
Alternatively, if you're already very familiar with the MS-DOS Batch Language, and need only a DOS command reference with syntax examples, see our Batch Reference:
Contents of Batch Reference – Batch File Command Reference
- Batch file commands alphabetically, with cross-references and examples of use
- Batch file commands grouped by Function (cross-referenced, and with examples)
- How to find the short-form 8.3 path to long-name files or folders
- How to find UNC network paths to use Batch file commands across networks
- Full treatment of delays and waits to delay Batch files:
- Pause a Batch file from 1 second to many hours (with choice or ping)
- Detecting when a Batch file delay is cut short with Ctrl C + N
- How to have a Batch file wait for a Windows GUI process to finish
- Batch file that waits for an event in another Batch file (running in parallel)
- How to document your Batch files with comments
- Remember the /? help switch that's built-in to Batch commands
- How to install the legacy MS-DOS version 6.22 Help system
Our clickable on-screen Reference to DOS Batch commands and terms also loads with every Lesson. Follow the Course and the Reference grows in detail as you progress, matching what you've learnt (there's no confusion with material not covered until later).
Make sure you take the first (it's the session in which you build the custom BatchWindow that the Course needs, and learn to use all the interactive features).
Syllabus for – ECHO and Environment variables:
- Use the ECHO command to write text to the screen
- Run Windows programs from the command line with the start command
- Manage file types (extensions) properly when saving with Notepad
- Write simple Batch files to learn how ECHOed text works in them
- Use CLS to clear the DVM display window contents
- Set, clear, and list environment variables with the SET command
- Expand environment variables to use their contents
- Print the DVM screen with Shift + PrintScrn
- Avoid common errors with the ECHO and SET commands
Syllabus for – Using Child Shells:
- Understand shell programs, comparing Explorer and COMMAND.COM
- Open, work in, and EXIT child command shells
- Use the PROMPT command to change the appearance of the prompt
- Understand the use of environment variables in child and parent shells
- Use an altered prompt appearance for immediate-mode work in a child shell
- Use a Return-code shell to make ERRORLEVEL changes visible
- Return ERRORLEVEL exit codes for Windows programs started from Batch files
- Clear the ERRORLEVEL to zero with a Single-use shell
- Write a Batch file to open a Return-code shell automatically
- Use command debug mode to single-step through a Batch file
Note From now, each Lesson needs your files from the previous one. Use your own files, if you can. If you can't (or if you want to retake a previous Lesson), download the files from the link at the start of the Lesson, and click

instructions.
Errorlevels Download our Windows 95/98/ME Batch command now (or in any Lesson whenever you click on the term ERRORLEVEL).
Syllabus for – Using choice and ERRORLEVELs:
- Use the choice command to get replies from a list of options
- Use a Return-code shell to see the reply codes returned by choice
- Define the reply list in choice with the /c: switch
- Define a case-sensitive choice reply list with the /s switch
- Test for ERRORLEVEL values with the greater-than-or-equal-to test
- Use IF NOT ERRORLEVEL to test for return codes less-than a given value
- Combine two ERRORLEVEL tests in one line to test for exact-equality
- Write a Batch file to ask a question and act on the answer supplied
Syllabus for – Finding the current ERRORLEVEL:
- Use choice to set given values for the current ERRORLEVEL
- Use sequential IF tests to set a variable to the current ERRORLEVEL
- Write a simple Batch file to show the current ERRORLEVEL for useful values
- Check the results of the ERRORLEVEL script in a Return-code shell
- Suppress spurious messages with the >NUL syntax
Syllabus for – Scripts as Useful Intermediate Tools:
- Use comments to explain lines of Batch code in scripts
- Use Commented Labels to create the logical plan of a script
- Design a Setup Batch file, to help build and test the main script project
- SET, use and clear variables holding values used in a script
- Control and alter the flow of logic in a Batch file with GOTO commands
- Correctly use (and avoid) fall-through from one code section to another
Syllabus for – Designing Menus in Batch scripts:
- Design a Batch file menu with ECHOed messages and choice
- Use a Return-code shell to study the ERRORLEVELs returned by a menu
- Use a "quoted prompt" to align choice prompt with menu text
- Act on user-replies to a menu with correctly ordered IF ERRORLEVEL tests
- Use ECHOed messages to check the flow of logic through a menu is correct
- Code menu IF tests so they fail safe if choice command is missing or corrupt
Syllabus for – Redirection and File Management:
- Use DIR to list files and folders alphabetically ordered with the /o switch
- Use DIR with the /b (bare or plain) switch and /s (include subfolders) switch
- Understand the folder dot aliases . and .., and use relative paths
- Redirect the STDOUT output channel to devices such as PRN or COM1
- Create files with the redirection operator >
- Append to existing files with the append operator >>
- Display the contents of text files with the TYPE command
- Combine files using TYPE and the append operator >>
- Use wildcards with DIR to limit the file types that it lists
- Create folders with MD and remove them again with RD
- Change the current folder with CD
- Create transient workfiles in the TEMP (temporary) folder
- Use the emending suffix .\ for reliable use of folder paths stored in variables
- Use DEL to remove workfiles (and keep the hard drive tidy)
Syllabus for – Managing Workfiles and Debugging Batch scripts:
- Begin coding the Build option of the Setup Batch file
- More techniques for debugging errors in Batch files
- Create transient working files in the TEMP folder with the emending suffix
- Use COPY to copy a file to a new destination name in a new folder
- Use COPY with a wildcard to copy multiple files in one operation
- Make subfolder structures with the MD command
- Use ECHO ON and @ECHO OFF to debug a section of problem Batch code
- Use deltree to remove subfolder structures
- Avoid stalling a script when deltree prompts for y/n confirmation
- Redirect unwanted deltree reports to NUL
- Use deltree safely while developing scripts that use it
- Use a confirmation sub-menu for user-confirmation of major actions
Syllabus for – Copying and concatenating files:
- Finish coding the Build option of the Setup Batch file
- Comment out script lines temporarily during development
- Use COPY with /y (=yes) to overwrite existing files without confirmation
- Use the /a-d switch combination of DIR to list only filenames, not foldernames
- Use the \*.* suffix to force a destination to be recognised as a folder
- Use DIR with the /s (=subfolder) switch to search for file(s) on disk
- Use COPY with + , or a wildcard, to concatenate files
- Use fc to compare two files, to see whether or not they differ
- Review the Batch file debugging techniques covered so far
- Use deltree to delete a list of files
Syllabus for – Testing for existence of files or folders:
- Understand use of IF EXIST to check whether or not particular files exist
- Understand use of IF EXIST FolderName\NUL to test existence of a folder
- Practise inserting breakpoints with ECHO and PAUSE to debug script errors
- Insert timed delays in a script with choice
Note For a detailed account (with many syntax examples) of how to insert fixed-time delays in batch files, how to wait for a Windows process to finish, or wait for an event (in another batch file running in parallel), see our Batch Reference.
Syllabus for – Finish Coding the Setup Batch script:
- Finish coding the Setup Batch script and thoroughly test it
- Further practice to consolidate the Batch skills already learnt
Syllabus for – Command-line Parameters and String Comparison:
- Use the Command-line parameter symbols %0 - %9 within a Batch file
- [Bracket] syntax for examining the expansion of empty environment variables
- Use IF Text==Text and IF NOT Text==Text comparison test
- Handle IF comparison for strings that may be empty
- Use ECHO to understand how a complex line of Batch code is parsed
- Use doubled %% syntax for literal display of text with % characters
- Use optional command-line parameters (detecting whether or not present)
Syllabus for – Plan and Menu Logic of Backup script:
- Plan the Backup script project
- Code the project plan as a commented label outline
- Use mixed-case labels to indicate the unique (operational) part of label
- Design the Backup script menu for the different backup functions
- Code the logic flow through the Backup script menu
- Examine syntax of the FOR command to do repetitive tasks
Syllabus for – Understanding File Backup methods:
- Discuss design of efficient backup strategies
- Examine the date stamp backup method with xcopy and the /d switch
- Practise date stamp backup of sample files in immediate mode
- Keep quick working notes in a disk file created with redirection
- Use find to search for text targets in files
- Use the fc command to compare multiple files
Syllabus for – Coding Backup option and a Drive-Ready test:
- Code and test preliminary version of the main option of the Backup script
- Format floppy disks from the command line with the format command
- Use variable expansions as components of a command line
- Use the /s switch of xcopy to include subfolders in a copy operation
- Use a Return-code shell to document ERRORLEVELs returned by a command
- Use xcopy to create a test to detect "drive ready" condition without stalling
Syllabus for – Using the Pipe operator:
- Understand use of the pipe operator to connect STDOUT to STDIN
- Correctly type the pipe operator in a DVM and in Notepad
- Use of simple test for correct pipe operator typed on unfamiliar machine
- Examine ERRORLEVELs returned from find using Return-code shell
- The 0=F0und 1=M1ssing mnemonic for ERRORLEVELs returned by find
- Use find with input redirection or a pipe to suppress dashed header
- Recognise aborted pipe operation file remnants in the TEMP folder
- Summarise DIR output by piping it through find
- Use Return-code shell to see intermediate ERRORLEVELs in pipe operations
- Use find to tailor an ERRORLEVEL from the text of another command (xcopy)
- Understand design of find targets for reliable location of character patterns
- Detect no-backup-needed condition and display suitable message
Syllabus for – Synchronizing a Backup, and more Pipe work:
- Discuss and code the Synchronize option of the Backup script
- Reply automatically to Batch command questions with a pipe
- Quick-format a disk non-interactively with replies piped from a file
- Quick-format a disk non-interactively with replies piped from ECHO+more
- Use a pipe to reply to xcopy's F ile or D irectory(=folder) query
- Use the REN command to rename files
- Understand and avoid filename/foldername conflicts in file backup
- Practise care using deltree with parameters in variables
- Use a one-line choice question to get confirmation for critical actions
- Make a menu option execute additional code from another option automatically
- Use of blank display line to avoid ECHO delays arising from disk activity
Syllabus for – Coding the Check and Restore options:
- Discuss and code the Check and Restore options of the Backup script
- Get useful information from xcopy and its /l=(list only) switch
- Use the move command to move files
- Further practice to consolidate Batch skills already learnt
Syllabus for – Finishing the Backup script project:
- Use choice to offer user options with timeout default reply
- Turn list display on/off using redirection to device name in a variable
- Add Usage instructions to Batch file to guide the user
- Automatically direct users to Usage instructions if they make input errors
- Manage Windows Explorer windows from the command line
- Run the Backup Batch script from a Windows Shortcut
- Use built-in Windows help system for assistance with Shortcut settings
- Understand Batch file Shortcut settings for Font and Environment size
- Configure command-line parameters in a Batch file Shortcut
- Use the ? parameter to enable the command-line parameter pop-up box
- Use the Mark, Copy, and Paste buttons in a DVM window
- Ensure DVM window closes automatically when a Batch file finishes
Syllabus for – Further Batch skills and Practice:
- Advanced uses of FOR command
- Use of "quotes" to group text and Space s together in FOR statements
- Remove "quotes" around text in variables with FOR
- Use, and suppress, special FOR treatment of / character
- Use wildcards in FOR statements to scan through matching filenames
- Hide files from FOR wildcard scan with attrib +h (hidden attribute)
- Use LFNFOR to make a FOR wildcard scan return Long File Names
- Use a FOR statement to replace multiple instances of similar commands
- Understand the 64 token limit in command lines (eg: a long FOR IN DO)
- Use an ECHO+choice pipe to return ERRORLEVELs in scripts
- Understand use of REM pipe to avoid failure of choice timed delays
- Create loops in Batch files to repeat command sequences
- Loop through an unknown number of parameters by SHIFTing and IF testing
- CALL a second script (returning to the first when the second one finishes)
- Use fc combined with a find pipe to return an ERRORLEVEL for comparisons
- Practise Batch ingenuity (use fc to check a string is a valid number)
When you've completed all the Batch Lessons and want to consult the full Batch Course Reference again to brush up on details, try our Batch Reference.
If you have questions or comments about this Batch File Course, please (your email subject line should contain: Allenware.com website). Please be sure to say whether you are using Windows 95/98/ME or Windows NT/2000/XP.
Links to Batch File information on the Web
Our own interest was originally stimulated by the highly intuitive techniques developed by Tom Lavedas, whose Website is well worth studying. For general links, Frank-Peter Schultze keeps an up-to-date, detailed list of Batch Bookmarks that's very useful.
Above all, enjoy writing your own Batch files. After completing the Course, the Batch Language will make sense. And Windows will be more productive, and far more fun!
Recent site changes and future plans are detailed in our page. Our Demonstration Courses are free, with no adverts. Before taking one, read our .
William Allen and Linda Allen
© Copyright 2003- Allen & Company. All rights reserved ©