Batch File Programming for Windows

Writing Scripts for Execution from the Windows Command Line

© Guy Lecky-Thompson

How-to article to help the reader get started with Windows command line programming, using batch files, and solving problems without programming in the traditional sense.

This article is designed to get the reader started with batch programming under the Windows command line environment. Command line programming is very useful because it allows the programmer to have access to the tens of commands available from the command line, as well as some proper programming structures for:

For example, it is possible to test values that are fed in from the command line, as well as parsing an entire file and performing commands on each token extracted from it. These are tasks usually handled by a higher level software application programming language such as C++ or Java. The batch programming language is rich enough to perform many functions, albeit sometimes in a cumbersome and inefficient manner.

It is, however, perfect for automating command line tasks (backups, copying files, ftp uploads, etc.) and basic editing jobs (adding headers and footers to HTML, publishing thumbnail directories etc.).

For a general overview and first taste of command line programming under Windows and DOS, the following article introduces the topic:

Each file is a plain text file, with the extension .bat, containing one or more commands from a simple 'language'.

Commands

The following commands are available for use in batch file programming:

There are no commands for receiving ad-hoc input from the user (the PAUSE command just waits for a keypress), nor any that allow interactivity in terms of mouse handling. For this reason, batch files are typically just used for non-interactive automated tasks.

The following is a list of articles related to individual batch commands:

Typically, layers of commands are built up consisting of batch files calling each other. Recursion is allowed (scripts calling themselves) with the usual caveat that an exit strategy must be provided for.

Tips & Tricks

Despite the primitive origins of batch file programming, the language can be persuaded to perform some complex tasks. These are usually supported by the so-called command extensions which are enabled under Windows XP by default.

The following articles highlight some of these advanced uses:


The copyright of the article Batch File Programming for Windows in Computer Programming is owned by Guy Lecky-Thompson. Permission to republish Batch File Programming for Windows must be granted by the author in writing.




Post this Article to facebook Add this Article to del.icio.us! Digg this Article furl this Article Add this Article to Reddit Add this Article to Technorati Add this Article to Newsvine Add this Article to Windows Live Add this Article to Yahoo Add this Article to StumbleUpon Add this Article to BlinkLists Add this Article to Spurl Add this Article to Google Add this Article to Ask Add this Article to Squidoo