Batch files are DOS command line commands batched together. In Linux they are known as shell scripts, and follow a completely different syntax. Early Windows users had to use a batch file (autoexec.bat) to allocate a drive letter to their CD-ROM's, in order to install Windows from CD. Batch files are not so crucial nowadays, although still supported by newer versions of Windows.
Under Windows XP/2000+, batch files (*.bat) run in a special window (aka Command Prompt) created by c:windowsystem32cmd.exe (this could be called command.com in some instances). Commands can be typed in individually, or listed sequentially in a batch file, requiring use of batch file language. This How-To will tell you how to create and run a Microsoft batch file, giving a simple backup as an example.
Examining the Full Code
Practice your copy and pasting skills on the following text.
- Closing the Window: If you want the program to close when finished, leave the script as is. If you would like to leave the window open for further commands, change the command <exit> in the final section to <cmd>, which leaves the window open.
- Current Directory: If the program references files in its own directory, you don’t need to put in the drive letter. So with the batch file in C: you can target files in c:temp just by typing: : Xcopy temp*.* d:temp /s/m
- The CHOICE command is not included in Windows XP Home nor Professional and will cause the batch file to close abruptly without prior notice.
- While the commands shown here are pretty harmless, use of certain system commands in batch files are potentially dangerous or possibly deadly to your device if misused.