Introduction to the MS DOS
Command Line Interface

A DOS 6.22 Lab Book

© 2000 – 2001 by D. Glen Cardenas  

Rev 4 – August 30, 2001
National Institute of Technology
 San Antonio, Texas

Table of Contents:

Chapter 1 – Talking to DOS
			Levels of Software	-------------------------------------------------	4	
			Booting the System	-------------------------------------------------	4
			IMPORTANT NOTES	----------------------------------------	5
			EXERCISE # 1 - Booting DOS	-------------------------------	7
			EXERCISE # 2 - Re-booting DOS	-------------------------------	7
			The Command Line	-------------------------------------------------	8
			DOS Commands	-------------------------------------------------	9
			DOS Syntax	----------------------------------------------------------	10
			IMPORTANT NOTE	-------------------------------------------------	11
			EXERCISE # 3 - Internal DOS Commands	----------------------	11
			EXERCISE # 4 - External DOS Commands	----------------------	12
			Getting Help from DOS	----------------------------------------	16
			EXERCISE # 5 - Using DOS Help	-------------------------------	16
			CHAPTER 1 QUIZ	-------------------------------------------------	17

Chapter 2 – The DOS File System
			Understanding Disks	-------------------------------------------------	18
			Getting a Disk Ready to Hold Data	-------------------------------	18
			EXERCISE # 6 - Formatting and Labels	----------------------	20
			Disk Maintenance	-------------------------------------------------	20
			System Maintenance	-------------------------------------------------	21
			EXERCISE # 7 - Maintenance	-------------------------------	22
			Directories and Files	-------------------------------------------------	22
			EXERCISE # 8 - Looking at File and Directory Information	----	23
			EXERCISE # 9 - Sub-directories	-------------------------------	23
			DOS Naming Conventions	----------------------------------------	24
			EXERCISE # 10 - File Names	----------------------------------------	25
			Wild Cards	----------------------------------------------------------	25
			EXERCISE # 11 - Wild Cards	----------------------------------------	27
			Working With File Trees	----------------------------------------	27
			EXERCISE # 12 - Using the TREE and the Pipe to MORE	----	28
			Terminating a DOS Command	-------------------------------	28
			EXERCISE # 13 - Aborting DOS	-------------------------------	28
			CHAPTER 2 QUIZ	-------------------------------------------------	29

Chapter 3 – Working With Files
			File Copy	----------------------------------------------------------	30
			EXERCISE # 14 - File Copying	-------------------------------	30
			Moving, Renaming and Deleting Files	----------------------	31
			EXERCISE # 15 - More File Operations	----------------------	31
			Bulk Deletion	----------------------------------------------------------	32
			EXERCISE # 16 - Using DELTREE	-------------------------------	33
			File Attributes	----------------------------------------------------------	33
			EXERCISE # 17 - File Attributes	-------------------------------	34
			File Input and Output	-------------------------------------------------	35
			Using Output Redirection	----------------------------------------	35
			EXERCISE # 18 - Redirection Output-------------------------------	36
			Using Input Redirection	----------------------------------------	37
			EXERCISE # 19 - Using MORE and Input Redirection	----	37
			Sorting Files	----------------------------------------------------------	37
			EXERCISE # 20 - Using SORT----------------------------------------	37
			The DOS Console	--------------------------------------------------	38
			EXERCISE # 21 - Using CON-----------------------------------------	38
			Echoing Text	-----------------------------------------------------------	38
			EXERCISE # 22 - Redirecting ECHO--------------------------------	39
			Using FIND	-----------------------------------------------------------	39
			EXERCISE # 23 - Using the FIND Command-----------------------	39
			DOS Command Memory and DOSKEY	-----------------------	40
			EXERCISE # 24 - Using DOSKEY	--------------------------------	40
			Disk Copying	-----------------------------------------------------------	41
EXERCISE # 25 - Using DISKCOPY and DISKCOMP	-----	42
			CHAPTER 3 QUIZ	--------------------------------------------------	43

Chapter 4 – Batch Files
			A DOS Convenience	--------------------------------------------------	44
			The DOS EDIT Command	-----------------------------------------	44
			EXERCISE # 26 - Introduction  to the DOS Editor	--------------	44
			Manipulating Text	--------------------------------------------------	46
			EXERCISE # 27 - Cut and Paste	--------------------------------	47
			BATCH File Commands	-----------------------------------------	47
			IMPORTANT NOTE	--------------------------------------------------	48
			EXERCISE # 28 - Writing a Simple BATCH File	--------------	48
			Result Codes and ERRORLEVEL	--------------------------------	49
			Making Decisions in a BATCH File	--------------------------------	50
			EXERCISE # 29 - Making Decisions in DOS	-----------------------	51
			Adding Remarks to a BATCH File	--------------------------------	54
			EXERCISE # 30 Adding Remarks to a BATCH File	--------------	54
			The FOR Loop	--------------------------------------------------	55
			EXERCISE # 31 Looping	-----------------------------------------	56
			EXERCISE # 32 Running One BATCH File From Another	-----	57
			The CALL Command	--------------------------------------------------	58
			Command Line Arguments for BATCH Files	--------------	58
			EXERCISE # 33 Using Command Line Arguments	--------------	59
			CHAPTER 4 QUIZ	--------------------------------------------------	60

Index of DOS Commands	-----------------------------------------------------------	61

Chapter 1 – Talking to DOS

Levels of Software

There are several levels of software in a computer. The most basic level is the software burned into read-only memory chips called ROMs that allow a computer to start up and look for the next level of software, the operating system or OS. These ROM chips also contain the BIOS or Basic Input Output System software that controls the actual hardware on the computer. Each computer has a BIOS written specifically for its hardware setup. This allows the operating system to control the hardware without having to know how it’s laid out. The OS simply passes a request for hardware control to the BIOS and the BIOS takes care of the details. This is why an OS can be loaded and work on different brands of computer without modification.

DOS is an operating system. It resides as the foundation software upon which applications run. Application software is the software that actually gets the day to day work done. These are things like word processors, accounting programs, games and the like. Many of these programs couldn’t run without the operating system supplying basic services like disk access and display control. The operating system then must likewise depend on the ROM BIOS for the nuts and bolts action of accessing the hardware. Thus we have the concept of tiered programming. One level of software depends on the level below it for basic functions. Each level then supports the level above it.

Booting the System

When you first turn a computer on, there is nothing in memory; no operating system, no application programs, no data. The only software available is that small group of power-up and diagnostic programs located in ROM on the motherboard. These start-up programs tell the computer just enough to go looking for the operating system on a disk. Only after the operating system has been loaded from disk into memory do we have a functioning computer that will run applications and execute our commands. This week, the operating system we will be using is Microsoft DOS version 6.22. 

Just to offer some background information about this process, think back to when you first installed DOS on your computer. The first thing you did was put DOS install disk #1 in your A: drive and reset. The install program loaded and began conditioning your hard drive by partitioning it into a primary partition, which became your C: drive, and leaving a bunch of free unused space after it. The reason for the free space is that DOS can only handle drives of no larger than 2.1 gigabytes and your drives are much larger than this. The extra space must be partitioned into “logical” drives in order for DOS to use it. The installer then formatted the primary partition and created a group of structures on the drive that allows DOS to keep track of its contents. These structures were a DOS boot record, two copies of the File Allocation Table, or FAT, and a root directory. A group of files were created in the root directory that allows DOS to boot from the hard drive. Finally, the installer created a sub-directory called DOS off of the root directory and as you continued the install process by inserting disks #2 and #3, the installer placed the files that constitute DOS in that directory. The net result of all of this activity is a hard disk that will load DOS automatically when the power is turned on. This is called having a "bootable" drive and the process the computer goes through when it loads the operating system from disk is called "booting up".

There are several steps a computer goes through between being turned on and loading the system from disk. In general, this process is referred to as the POST or Power On Self Test. It consists of a series of motherboard/processor/memory diagnostics as well as a search for connected hardware. 

Once the computer is running, you may have to re-start the system by re-booting the computer. There are two different techniques for doing this. When you first turn the power on or shut the power off and then turn it back on, you perform what is called a “cold” boot or a “hard” boot. This kind of boot starts the entire computer from scratch.  Depending on whether the monitor has warmed up enough, the first thing you will see is the video card banner. The same kind of re-boot will take place if you press the RESET button on the front of the computer. However, often you will not see the video card banner during a simple reset. In either case, the computer will do a full memory test before continuing the POST.

On the other hand, a “warm” boot or a “soft” boot is performed by the “three-finger salute” which consists of pressing the CTRL and the ALT and the DEL keys at the same time. Sometimes when installing new software, you will need to perform a soft boot in order to activate some of its features. There will also be times when the computer simply locks up or otherwise starts behaving strangely. This will necessitate a soft re-boot although sometimes a lock-up can be so severe that you must perform a hard boot with the reset button to recover.

A soft boot doesn’t reset the video board or run a memory test. Other than that, both boots follow the same remaining track. As the POST progresses, the hardware, ports and disk drives on the computer are identified and the computer will issue a single BEEP to say it’s happy. At this time POST will end. Next, the computer will look for an operating system to load. Unless the computer has been set to do otherwise, it will always first look at the floppy drive for a bootable floppy. If it finds no disk in the floppy drive, it will then go to the hard drive and see if it is bootable. If that fails, some computers will look for a bootable SCSI disk or bootable CD or even a bootable ZIP disk. Once the computer has exhausted all of its options and still has not found a bootable disk, it gives up and issues an error message to that effect. There's one part of this process that can really throw you if you don’t watch for it. When the computer looks for a bootable floppy and instead finds a non-bootable disk in the drive, it issues a “Non system disk” error and stops. You must eject the disk and hit a key before DOS will proceed with the rest of its search.

IMPORTANT NOTES: 

1)	Do not kill the power to a computer and then immediately turn it back on. To do so can cause dangerous power spikes to flow through the boards and can damage components. Always give a count of ten between turning power off and turning it back on.
2)	In all of the exercises in this book, the text in italics is information or some sort of step you are to perform. When you are to type something into the computer, it will NOT be in italics. However, in order to make DOS commands stand out in the text, they will be in bold type and not in italics. Sometimes these DOS commands are to be typed into the computer, sometimes they are simply part of the text or part of an explanation. You must read the text carefully and use your common sense to determine what you are supposed to type into the computer and what are instructions that you simply read and perhaps carry out. Don't type into the computer stuff like "and hit ENTER" simply because it came at the end of a statement you were typing into the command line. That part of the text is an instruction - something YOU are supposed to do, not something you are supposed to ask the computer to do.
3)	DO NOT make assumptions! If the instructions don't tell you to re-boot your system, don't do it just because you feel like. If the instructions don't ask you to put a floppy in the drive, don't have one in the drive. Follow the steps EXACTLY as written, don't improvise and you will do just fine.
4)	Make sure you are aware what drive and/or directory you are logged on to when you perform any exercise. All exercises will tell you EXACTLY where you should be logged on when you start and where to change directories or drives as you move through the steps. If you are asked to log on to a specific drive or directory, do so AT THAT TIME and DO NOT CHANGE IT UNLESS YOU ARE TOLD TO DO SO.
5)	Do not start an exercise anywhere except at the very first step. Do not leave out parts of steps, skip any steps or do any steps over again unless you check with the instructor to see what damage you might do by starting over, even starting over at the beginning of an exercise. Once you do a step, it may not be un-doable without considerable work and help.
6)	Remember, DOS is a very redundant system. If you are told EXACTLY how to do something in one step and then a few steps later are asked to do that same thing again, you will do it EXACTLY the same way you did it the first time except perhaps you will do so using a different file name or a different directory name but otherwise, you will use the same command and the same format to perform the same function. Try to remember how to (for example) change drives or log on to a directory or load a file into the editor. When asked to do it again, do it the same way even if you aren't given step by step instructions each time you are asked to do it. At some point, you must be expected to have learned how to do things and not need to be hand-held through the process every time.
7)	Read a least 3 or 4 steps ahead of the step you are currently attempting to perform and read them COMPLETELY before attempting to carry out your next step. Make sure you know where the process in heading and what you can expect to have happen by carrying out any given step. DO NOT IGNORE THIS LAST STATEMENT - STOP - READ IT AGAIN AND THEN READ IT A THIRD TIME!!!!!!!! You MUST read ahead EVERY TIME you perform a step in order to fully understand what you are doing. DON'T FAIL TO DO THIS.  Now, go back and read this statement a forth time!
8)	Sometimes you will be asked to do things the "wrong" way on purpose. This is one way of teaching you what happens when things go wrong. Don't let this throw you. It is another good reason to read ahead so you will expect an error message or strange result.
9)	Not each and every DOS command will reply to you when you carry it out. Just because you type in a DOS command and after hitting ENTER you get nothing back except the cursor, don't think the command didn't take. You can depend on DOS letting you know something didn't work out if it didn't. Sometimes no response from DOS is the correct response for that command.

EXERCISE # 1 – Booting DOS

1)	Power up your computer and allow it to finish loading DOS. You will see a prompt on the screen that looks like this, C:\> and a blinking cursor after it. This is called the DOS prompt or command prompt. You are currently logged on to the root directory of drive C:
2)	Place a blank floppy disk in the A: drive and at the DOS prompt type in the command SYS  A:  and hit ENTER. This will make the floppy disk bootable. Mark this disk "BOOT DISK". Keep this disk and another completely blank disk marked “COPY DISK” handy for this exercise.
3)	Turn the power off to your computer.
4)	Put the blank COPY DISK floppy in the A: drive.
5)	After a 10-count, turn the power on.
6)	Note the steps the POST takes as shown at the very top of the display screen. For one thing you will see a count of the amount of RAM in your computer.
7)	After the POST, the system will attempt to boot DOS from that floppy. Note the error message on the screen.
8)	Without removing the floppy disk, respond to the error message by hitting a key and see what happens.
9)	Now remove the floppy disk and then hit a key. The system will boot to the DOS prompt. Note that the prompt shows you are again logged on to the root directory of drive C:
10)	Place the bootable floppy disk marked BOOT DISK you made in step 2 into drive A:
11)	Cycle the power on the computer being sure to count to 10 between power-off and power-on.
12)	After booting is finished, you will be asked for the time and date. Just hit ENTER in both cases to accept the current date. Note that the prompt shows you are logged on to drive A:
13)	Remove the floppy disk and set it aside.
14)	With the A: prompt on the screen and NO floppy disk in the A: drive, hit the CTRL, ALT and DEL keys all at the same time.
15)	Note the place where POST starts this time by seeing there is no display of memory amount.
16)	After the DOS prompt is displayed, hit the RESET button.
17)	Note the place where POST starts this time. Again there is a display of memory amount.
18)	You should see how using CTRL-ALT-DEL causes a warm boot (skips the memory test) and that hitting RESET causes a hard boot like the cold boot when the computer is first powered up (performs a memory test).

When DOS starts to load, it first finds on the bootable drive two “hidden” files called IO.SYS and MSDOS.SYS, copies them into memory and runs them. Next DOS reads a file called CONFIG.SYS which sets up most of the hardware DOS can use as well as memory managers. It then loads a file called COMMAND.COM into memory that allows DOS to read commands and carry them out. 

The first commands that DOS carries out are given to it automatically at the end of the boot process. As a general rule, the boot-up sequence concludes with DOS executing a batch of commands written in a text file called, interestingly enough, a BATCH file. In this case, the batch file is called AUTOEXEC.BAT and as the name implies, it is designed to automatically execute every time the computer boots. In this batch file you will find commands that configure the look of the prompt, load in programs called TSRs (we’ll discuss these in class later) and perform other set-up operations. Incidentally, the commands in a batch file are exactly the same as commands you could type in at the command line. In fact, batch files exist to automate the executing of DOS commands that would otherwise have to be typed in each time by the user. Batch files simplify the running of often-used DOS commands. In the case of AUTOEXEC.BAT, DOS knows to look for this file at boot time and if it finds it, it will run it. You can also run it from the command line like any other batch file. However, there is limited occasion for doing so. After all of this is over, you have the famous DOS prompt ready and waiting for your brilliant commands.

However, you may have noticed that when you booted from the floppy you were asked for the time and date. This is because the bootable floppy did not have the CONFIG.SYS or AUTOEXEC.BAT files on it. As a result, the system booted up into a “clean” configuration with only the most bare essentials of DOS installed. We can make DOS behave almost the same when booting from floppy as when it boots from the hard drive by copying those 2 files to the BOOT DISK by hand.

EXERCISE # 2 – Booting DOS with CONFIG.SYS and AUTOEXEC.BAT
1)	Be sure that your computer has booted from the hard drive and you have the C:> prompt on the screen. IF you want to be sure, remove any floppy disks from your drive and restart your computer.
2)	Put the BOOT DISK in your floppy drive.
3)	Type in the following 2 commands one at a time, hitting ENTER after each one:		COPY  CONFIG.SYS  A:									COPY  AUTOEXEC.BAT  A:
4)	Now with that floppy still in the drive, push the reset button and perform a hard boot.
5)	As DOS loads in, notice how the time and date prompt no longer appears and how the commands in CONFIG.SYS and AUTOEXEC.BAT are run.
6)	Once DOS has loaded, remove the floppy from the drive and hit the reset button to reboot from the hard disk.

The Command Line

After booting DOS, you likely found yourself facing a computer screen containing not much more than a blinking cursor. It must occur to you, “Now what?”

This blinking cursor, often referred to the “command line”, “command prompt” or "DOS prompt" (all of these terms mean the same thing) is as far as DOS goes. Everything else is up to you. You must now enter commands and instruct the computer as to what to do, thus the term “command prompt.” Remember computers are stupid. They have no idea what they’re expected to do. They respond only to program commands, many of which you must type in yourself at the prompt.

The command prompt itself will look different from computer to computer depending on whether the user has “customized” the prompt. Assuming this hasn’t happened, the default prompt as configured by DOS at the time it is installed will consist of three parts. This is what it will likely look like:
C:\ > _
The first part of the prompt is the current (or default) directory. This is the location where DOS is currently “logged on”. In this case, DOS is logged on to the root directory of drive C: and any command’s operation involving files will be focused towards this directory unless the command is typed in with a parameter that tells it to do otherwise. If we change directories and log on to, for example, the DOS directory, then the prompt would look like this:
C:\DOS > _
The next part of the prompt is the “>” sign. This is a character that DOS adds to the end of the log-on directory just to make things readable. It serves as a marker showing where the prompt stops and whatever you type in starts. The last part is the blinking cursor. The cursor will always show you where your next keystroke will go. As you type, the cursor will move over to the next empty spot on the screen. The cursor can be controlled with the SPACE bar and the BACKSPACE key. In many applications such as word processors, the arrow keys can also be used to move the cursor around.

DOS Commands

Now that you know how to boot up the computer and get a command prompt, we should try to issue a few commands and see what happens. First we need to define the types of commands that DOS contains. They fall into two categories; internal commands and external commands. Internal commands are those that can be run from just the information DOS has in memory by virtue of having loaded COMMAND.COM. This file contains not only the software to allow DOS to read the contents of the command prompt, but also the code to execute many basic DOS commands. Because this program is always running in memory, the commands it can run are called internal. They include such commands as Change Directory (CD), List Directory (DIR), Clear Screen (CLS), File Copy (COPY) and so on.

Other commands that are not part of COMMAND.COM are loaded into memory each time they need to run and are thus called external commands. Such commands include Format (FORMAT), Check Disk (CHKDISK), Virus Scan (MSAV) and others.

At this time, it’s important to point out something about external commands. The command’s name is actually the name of the file that contains the code necessary to carry it out. If you look in the DOS directory, you will see files with names like FORMAT.COM and CHKDISK.EXE. These files contain the command’s program code. This is true not only for DOS, but for all programs. Literally speaking, any executable file regardless of where it comes from is treated by DOS as if it were an external DOS command. For example, if you want to start Word Perfect, you enter WP at the command prompt and DOS will find and execute the program WP.EXE, which is the file containing the Word Perfect program code. Looking at this from the other side, DOS external commands are simply application programs you can run like any other software. It is important you realize that to the operating system, all programs are external commands and all external commands are just programs. To make this concept easier for the user, DOS will find and execute programs using just the file name without the extension, which is the “dot” and the letters that come after it. This is why you can run the Check Disk program by just entering CHKDISK and not having to enter CHKDISK.EXE. The rule is that if DOS can find a file of the name you type in that either has an EXE, COM or BAT extension, it will execute that file as a command. Files having one of these extensions are called “Executable” files. If DOS finds both an EXE and a BAT file of the same name, it will execute the EXE file and ignore the BAT file. There are also rules that guide DOS if it finds the exact same file and extension but in different directories. In this case, it will first look in the logged on directory as displayed in the prompt, then use the PATH statement (in the AUTOEXEC.BAT file) which lists other directories and drives DOS is to search each time a command is issued. As it searches the path, it will stop looking when it finds the first executable file that has the name of the command.

As would seem logical, if you type a command that is misspelled or if you type in gibberish, DOS will at least try to find a command called what you typed in. It will search the list of drives and directories listed in the PATH statement loaded when AUTOEXEC.BAT was run and then when it is forces to give up, will issue the famous "Bad command or file name" error. Another thing to keep in mind is that if you issue a command for a program file that you know is on your system and get this message, then you likely need to log on to the directory that contains the program file or add that directory to your PATH statement so DOS can find it no matter what directory you're logged on to.

DOS Syntax

Next, let’s look at the syntax of the command line. Syntax is the term for the rules of the language. Just as with human speech where a conversation can only make sense if all participants are using words together according to set rules, the command line will only respond to your input if you type it in according to the rules of DOS syntax. These rules are simple. As an overview, they are as follows:

1)	A command consists of one or more parts. At a minimum, there is the command name itself. Often, the command will need one or more “parameters” to tell it what it should do or what it’s supposed to operate on. These parameters, often called “arguments” in programming circles, can include disk drive letters, file names and sometimes “switches” which are the SLASH "/" with a single letter parameter that turn some feature of the command on or off. Throughout this book I will use the terms “argument” and “parameter” interchangeably. As they relate to parts of a DOS command, both words will refer to the same thing. Most commands can have several such parameters all listed after the command's name. Changing these parameters will change the way a command works.
2)	The parts of the command must be spelled EXACTLY because DOS can’t guess what you might have meant.
3)	For the most part, DOS doesn’t care if you use upper case or lower case or any mixture of the two.
4)	You must use a space or other separation character between the parts of a command so DOS can tell where one part ends and the other starts. The specific character often depends on the command but mostly it is a simple space. NOW GO BACK AND READ THIS STATEMENT AGAIN! Tattoo it to your arm if you need to, but DON'T FORGET TO SEPARATE THE COMMAND FROM THE ARGUMENTS AND ONE ARGUMENT FROM ANOTHER WITH A SPACE!
5)	The DOS command itself is made up of a single word of up to 8 characters. Even if the command “seems” to be a combination of more than one word, it is entered without any spaces. For example the Disk Copy command is entered as DISKCOPY with no space between the words BUT, AGAIN, A SPACE BETWEEN THIS COMMAND AND ANY ARGUMENTS THAT COME AFTER IT. If you put the space in the command and try to type DISKCOPY as two words, DOS will think the actual command is DISK and the word COPY is simply an argument or parameter to be applied to the command DISK.
6)	Once you type in your command, you must hit the ENTER key so DOS knows you’re finished. Just staring dumbly at the screen after you finish typing in your command won't tell DOS anything. The exception is when DOS asks you a question that can be answered by a simple keystroke such as “Y” for yes or “N” for no. This isn’t a universal truth, however. Sometimes DOS needs the ENTER key after the Y or N. The difference is that the ENTER key is expected if the response could effect the system or your disk in some way. DOS demands the confirmation of the ENTER key as a safety measure to make sure you intended to hit the Y or N and didn’t simply hit the key by accident.

Now that we have some idea of how to talk to DOS, let’s see what happens when DOS is given some commands. 

IMPORTANT NOTE: You DO NOT have to use Capital Letters when you enter your commands. I use caps and also place commands in bold type to help you find them in the text and read them. DOS doesn’t usually care if you use upper or lower case and when it makes a difference I will point that out clearly.

EXERCISE # 3 – Internal DOS Commands

1)	You will be giving DOS some commands in these next two exercises. It is likely you may feel that you have no idea what you're doing at this point. This is OK. Just perform the steps exactly as written and after the exercises we will review the commands that were used and more about what they do.
2)	Make sure you are logged on to the root directory of drive C: (the prompt on the screen reads C:\ > and then a blinking cursor) and that you last booted from the hard disk and not from a floppy disk. If you're not sure, remove any floppy disks from your A: drive and use CTRL-ALT-DEL to reboot your computer. 
3)	At the DOS prompt, issue the command VER
4)	As you can see, this will always return the current version of DOS on the computer. In this case it is 6.22 which is the last version of stand-alone DOS that Microsoft released. Some computers may be running versions 5, 6 or 6.2. In fact, you may even find computers still running versions between 2 and 4 although this is becoming more and more unlikely.
5)	Place the bootable floppy disk you made during Exercise #1 into drive A:.
6)	Switch (log on) to that drive by typing A: and hitting ENTER.
7)	At the “A:” prompt, issue the command to view the directory by typing DIR and hitting ENTER.
8)	Note the names of the files listed. There are other files on that disk which are Hidden Files. They include the boot files IO.SYS and MSDOS.SYS. These are files that DOS finds so important that it suppresses listing them in the directory so there is little chance that they will be accidentally moved or deleted. However, we will issue the DIR command with a parameter called a “switch” that will customize the command and allow us to see these hidden files.
9)	Issue a modified version of the command by typing DIR  /A:H  and remember that you now have a command with two parts. You must be sure to put a space between the "DIR" part and the "/A:H" part for DOS to understand the command.
10)	Notice that the hidden file names are displayed.
11)	Log on to the C: drive by typing in C: and hitting ENTER.
12)	Issue the DIR command and look at the files listed. Note that some of the items listed are not file name but the names of the sub-directories such as DOS.
13)	Issue the DIR  /A:H command and look at the hidden files.
14)	Issue the DIR  /W command and notice the different format for the display of file names and the suppression of details such as file size and date.
15)	Log on to the DOS directory by issuing the Change Directory command. This command has two parts. There is the command part which is "CD" and a parameter which must be supplied to tell the command which directory to change to. In this case, it will be the DOS directory. Enter the command as CD DOS
16)	The prompt will now show that you are logged on to the DOS directory.
17)	Issue the DIR command.
18)	Because the DOS directory has so many files, the names scroll off of the screen before you can read them. To correct this problem, we will issue the DIR command with the /P switch. This switch will cause the screen to fill up and then pause so we can read each screen-full. Type in DIR  /P and once the first screen-full of file names is displayed, do nothing else until the next step.
19)	To see the next screen-full of file names, press any key. Do this only once before going on to the next step.
20)	You could continue to press a key and get screen after screen of file names until the last screen-full is displayed and the command exits back to the DOS prompt. However, if you wish to abort from this (or almost any) DOS command before it has finished, press and hold the CTRL key and then press the "C" key. This will return you to the prompt. Do this now.
21)	Return to the Root directory with the CD command and a "backslash" as the parameter. This will always return you to the root directory no matter how many directory layers down you are. Issue the command CD\ (a space between the "CD" and the "\" is optional on this occasion).
22)	Issue the DIR command with the argument C:\DOS after it so it reads DIR C:\DOS
23)	You can see that even though you are logged on to the rood directory, you can still get a listing of the DOS directory by specifically telling the DIR command to list the contents of a different directory or even a different drive than the one you are logged on to.
24)	Clear the display by issuing the command CLS
25)	Now let’s try the TYPE command. Issue the command TYPE  AUTOEXEC.BAT
26)	As you can see, this command displays the contents of a file. In this case, the file is a “batch” file which is a text file containing DOS commands.
27)	Try issuing the command TYPE  COMMAND.COM
28)	This time you got a bunch of silly characters on the screen and a beep. The file COMMAND.COM is not a text file but a program file and so contains bytes that do not translate into words or even normal characters all of the time. The beep was caused by a byte of data that the TYPE command interpreted as a “ring bell” request character.
29)	Clear the screen with the CLS command.

EXERCISE # 4 – External DOS Commands

1)	Place the blank COPY DISK floppy disk in drive A:
2)	Issue the command FORMAT and as you hit ENTER, watch the drive LED on the front of the computer. It will flash briefly as DOS reads the file FORMAT.COM off the hard drive and loads it into memory where it can be run.
3)	As you can see, FORMAT didn’t do anything. This is one command that requires parameters in order to function. You must tell it what to format.
4)	Issue the command again but with the arguments it needs to access the floppy disk. We will also tell FORMAT to make the disk bootable and to perform a long format. Type the command FORMAT  A:  /S  /U and hit ENTER. Note that this command now has four parts. Separate each part with a space. The prompt will ask you to put a disk in the drive (it should already be in the drive as of step 1 above) and hit ENTER. Do this now.
5)	As you can see, the process has begun. The “A:” parameter told FORMAT that it is to work on the disk in the A: drive. The “/S” parameter told it to copy the system files to the disk and thus make it bootable. The “/U” parameter instructed the program to perform an “unconditional” or long format that completely destroys all previous data. This is a good idea for any floppy that you might suspect has a virus. A virus cannot survive a long format.
6)	When the process is over, inform FORMAT that you will not be formatting any more disks by hitting the “N” key for “NO” and let it exit back to the DOS prompt. Remove the floppy disk and change the name to “BOOT DISK 2”.
7)	Next we will look at some DOS commands that are “Menu Driven” which means they will sort of look more like a real application. Issue the command EDIT and when you hit ENTER watch the drive LED blink on the front of the computer.
8)	Hit the ESC Key to leave the greeting screen and enter the editor screen. EDIT is a simple but very useful DOS word processor. With it you can create, modify and print text documents. It will be most useful when we get around to viewing and changing the contents of the CONFIG.SYS and AUTOEXEC.BAT files in class.
9)	Try typing around in the editor. Use your mouse and see how the mouse pointer moves around.
10)	For now, close the editor without saving the words of wisdom you have created.
a)	If you have installed your mouse, use the mouse to click on the FILE menu label in the menu bar near the top of the screen. From the drop-down list of functions that this action causes to be displayed, click on EXIT. You will be asked if you wish to save the contents of the screen. Click on NO and the program will end, bringing you back to the DOS prompt.
b)	If you are not using the mouse, hit the ALT key and the “F” key to open the FILE menu. Hit the “X” key to select EXIT and hit the TAB key to select NO from the “Save” box and hit ENTER.
11)	Let’s try the EDIT command again but this time with a file name as an argument. Issue the command as EDIT CONFIG.SYS. This time there is no greeting screen and the contents of the file CONFIG.SYS has been automatically loaded into the editor’s workspace ready to be viewed, modified or printed.
12)	Without attempting to modify this file, close the EDIT program using the technique discussed in step 10 above.
13)	Now try the Scan Disk program. Issue the command SCANDISK. This will start a program that checks the integrity of your disk structures and file system.
14)	SCANDISK as well as many other DOS programs has a very simple interface. Don’t be afraid of them. Most choices can be selected by hitting the TAB key to highlight the choice and then the ENTER key to execute the selection. A bit of poking around and common sense will answer most questions. 
15)	After SCANDISK checks drive C: it will ask if you want to perform a detailed surface scan. Reply NO. When the program finishes it will give you a report stating the current health of the drive.
16)	Close the program.
17)	Run the program again but this time specify on the command line the disk to be checked by adding an argument to the command. Put your boot floppy in drive A: and then issue the command SCANDISK A:
18)	This time, request a detailed surface scan.
19)	Close the program after the results are displayed.

Let’s review the commands we just used. The very first one we used in Exercise #1 was the SYS command. This command transfers copies of the system files that allow a disk to boot DOS. The command requires at least one argument informing it as to where to send the system files. In this case, we sent them to the floppy disk in drive A: with the A: argument. The system files came from the drive and directory where we were logged on at the time we issued the command. This was the root directory of drive C:. If we had been logged on to a directory that did not contain those system files, the command would have failed. However, we could have added another argument stating the source of the system files. This way we could have issued the command from any directory. This command is designed to make a disk bootable without reformatting it and thus loosing all of the data on it. And is an internal command, which means DOS doesn't have to load it from the hard drive to run it. The software for this command is a part of COMMAND.COM and so is always available in RAM.

We followed that command with the COPY command, also an internal command. With this one we copied 2 files which we listed by name from the currently logged on drive to the A: drive. There were 2 arguments here. The first was the file name and the second was the destination for the files. Again, we didn’t need to specify the source for the files because they existed on the drive and directory where we were logged on. Otherwise, the second argument would have pointed to the source of the files and the destination would have become the third argument.

The next command we tried was in Exercise # 3. It was the VER command. This command simply reports the version of DOS currently running on the computer. This may be important to know. Some software requires a minimum level of DOS in order to run. Also you may attempt to run DOS programs on a system that booted from a floppy disk containing a different version of DOS than the version on the hard disk. In this case, any external command will report an “Incorrect DOS version” error.

Next we tried switching drives. This is done by simply typing in the drive letter we wish to log on to. REMEMBER!!! A drive letter consists of not only the letter of the drive but must also include the colon. Forgetting that colon will confuse DOS to no end. COMMIT THIS TO MEMORY: To log on to a different drive, type in ONLY the drive letter and a colon. It doesn't matter what directory you are logged on to, doing this will ALWAYS log you on to another drive, and also will log you on to the directory of that drive you were using the last time you were logged on to that drive. For example, suppose you were logged on to the DOS directory of drive C: and you switched to drive F:. Later you log back on to drive C: and when you do, you will again be logged on to the DOS directory which is where you were on drive C: when you left that drive for drive F:.

In that same exercise we encountered the command to change directories, or the CD command. To use it, we must supply an argument in order to tell DOS what directory we wish to switch to. To log on to a directory one level further down the hierarchy, we just add that directory to the command. For example, if we want to log on to the WORK directory, we type in CD WORK and that does the job. However, what if the WORK directory is not a sub-directory of the directory we are currently logged on to, DOS will not be able to find it with such a simple argument. DOS needs more information.

BURN THE FOLLOWING DISCUSSION OF THE CD COMMAND INTO YOUR BRAINS!

Let’s say we have a directory structure as follows. Off of the root directory of drive C: we have a directory called WP. WP is then a sub-directory or “child” directory of the root. It can also be said that the root directory is the “parent” directory of WP. Further suppose that the WP directory has several sub-directories or child directories. One of them is called WORK. Now it so happens that WORK has a sub-directory called LETTERS and that directory has a sub-directory called JOBLEADS. We want to log on to the JOBLEADS directory from the root. What do we do? Well, we could issue separate CD commands for each directory level such as CD WP followed by CD WORK then CD LETTERS and finely CD JOBLEADS. An easier way is to supply one argument to one CD command that tells DOS the exact location of JOBLEADS relative to the root directory. DOS uses a special character to separate the names of directories and file names in the “path” to that final destination directory or file. It is the backslash. We’ve already seen this character in the prompt. Now let’s use it in the argument to the CD command. To reach the JOBLEADS directory from the root we would issue the command:
CD WP\WORK\LETTERS\JOBLEADS
And DOS will then be able to log on to that directory in one jump. Your DOS prompt would then look like:
C:\WP\WORK\LETTERS\JOBLEADS>
And any default file activity DOS undertakes at this point will be focused on the JOBLEADS directory and its contents. Now we want to go from here to the WP directory. The quickest way to do that is to use the dot or period character. For some strange reason known only to the minds of programmers, any directory knows the names of its sub-directories, but not its own name or the name of its parent directory. It refers to its parent with two dots like “..” and uses one dot like “.” to refer to itself. Therefore, if we wish to change to the parent directory we simply issue the command CD.. with no spaces between the CD part and the dots. If we want to step back several parent directories, we must issue multiple CD commands to move one level at a time through parent directories until we reach our destination. However, if we wish to return to the root from any other sub-directory, we can issue the command CD\ and this will bypass any and all directories between where we are and the root in one step. The only way to quickly move to a parent directory that is several levels below our current location is to issue the CD command with the full path of our intended destination. For example, to go from the JOBLEADS directory to the WP directory in one step, we would issue the command CD C:\WP and that would take us there. In fact, if you give the CD command the full path with drive letter to any directory, it will take you directly to it from any other location on that same drive. However, the CD command will not change drives. WHENEVER AN EXERCISE ASKS YOU TO “LOG ON” TO A DIRECTORY, YOU ARE EXPECTED TO USE CD TO CHANGE TO THAT DIRECTORY. WHEN YOU ARE ASKED TO LOG ON TO A DIFFERENT DRIVE, USE THE DRIVE LETTER TO DO THAT. CD WILL NOT CHANGE FROM ONE DRIVE TO ANOTHER. IT WILL ONLY CHANGE FROM ONE DIRECTORY TO ANOTHER ON THE SAME DRIVE.

An often-used command is the DIR command. This is the one that displays the contents of a directory. As you saw in the exercise, there are several variations on this command and several ways to use it. We tried the /A switch that allows us to view files that have specific attributes. In the exercise we had to give the /A switch a parameter of :H to tell it to display only hidden files. Other parameters are :R for read-only files, :A for files that need to be archived (have changed sense the last backup was make), :S for system files and :D for directories only. Without the /A switch DIR will display all non-hidden files and sub-directories.

We also saw the use of the /W switch for formatting the list into a wide display, however, doing so caused suppression of the file details such as the file size and creation time and date. Using the /B switch will do the same thing but keep the single column format. Using the /P switch allowed us to pause the display after each screen-full of names so we could examine the list of directories that contain more than one screen's worth of items. Other switches you may find useful are the /S switch which will display not only the contents of the target directory but also the contents of all sub-directories beneath it, and the /O switch which when combined with another parameter will order the list by name, by extension, by size, by date and so on.

Finely we saw that if you offer a target drive and/or directory as an argument to the DIR command, we can list the contents of any location in the system regardless of where we're logged on. Without it, the DIR command will assume the current default directory is the target.

The next internal command we used was CLS for Clear Screen. There are no parameters available for this command. It simply clears the display and places the cursor in the top left corner of the screen. Finely we used the TYPE command to display to the screen the contents of a text file, in this case the batch file AUTOEXEC.BAT, and then a program file which proved to be somewhat less than successful. This is because a non-text file will contain many or even exclusively data bytes that do not contain any human readable information.

To check out some external commands, we ran FORMAT, EDIT and SCANDISK. Remember, external commands are those commands that must be loaded into RAM from the disk each time you want to run them. The FORMAT command required arguments in order to function. We had to tell it what to format and optionally, how to format. The other two can be called without arguments. However, as we saw, using them helped to somewhat automate the running of the commands. In the case of EDIT, offering a file name on the command line caused the editor to open that file as it started. There are some switches for EDIT, but the are used only to format the display for non-conventional monitors. One thing we didn't look at was the fact that EDIT, like many of the full-featured DOS commands, has on-line help. Hitting the F1 key or the ALT and "H" keys while using it will call up the help system. This program also made use of the mouse.

Getting Help from DOS

As you can see from the above exercises, DOS commands will usually offer or even require arguments (or parameters) to tailor their operations. No one will expect you to memorize every DOS command or all of a commands possible permutations. However, you need to know the most common commands and their most common variations. Even so, it is good to know that there is a ready source of this detailed information on all DOS commands right on your computer. It is DOS HELP. You can use the help in two ways. For many commands, you simply issue the command with a “/?” parameter and you will be presented with a rundown on that command. If you can’t remember the exact command or want to see a list of all DOS commands, issue the HELP command and DOS will list all of its commands and you can page through them, select each to view detailed information on them and otherwise review them. 

EXERCISE # 5 – Using DOS Help

1)	From the prompt, type in the command XCOPY /?
2)	You will see the help documentation for that command. Read through it and see all of the ways you can use this powerful file copy command. Note that in all cases, XCOPY will require arguments. 
3)	Now type in the command HELP and you will be taken to a screen listing all DOS commands.
4)	Note that at the top of the screen is a list of the keys that control this list. This list tells you how to move the highlight, view details and exit the screen back to the DOS prompt.
5)	The arrow keys can be used to navigate through the list. Find a command that interests you. Highlight it by moving over to it and hit ENTER. You will see a detailed discussion of using this command.
6)	Exit back to the prompt.

Throughout the rest of this book we will be looking at many DOS commands and you will be directed to use the help system to gain detailed information of how to use the command. As long as you remember HELP or the /? switch, everything else is at you fingertips.

CHAPTER 1 QUIZ: Answer T for True or F for False

____ 1)	When you first turn a computer on, the only software running is in ROM.
____ 2)	The main difference between a cold boot and a warm boot is that a cold boot doesn’t
	do a full memory test.
____ 3) 	To perform a cold boot, you use the CTRL, ALT, DEL keys.
____ 4) 	If you have a non-bootable floppy in the A: drive at boot-up, the disk will be ignored
	and the system will try to boot from the hard drive.
____ 5) 	The command prompt is the primary interface between you and DOS.
____ 6) 	There is a difference between the DOS prompt and the command prompt and that is
	only the DOS prompt shows you the current default directory.
____ 7) 	Internal commands are those that DOS loads from disk into memory before they can
	be run.
____ 8) 	COMMAND.COM is loaded into RAM at boot time and contains the software needed
	for DOS to interpret what you type at the prompt.
____ 9) 	DOS treats any executable program file just like an external command.
____ 10) 	The default drive and directory is where DOS will focus its file activities.
____ 11) 	Commands that need parameters must have those parameters listed just before the
	command.
____ 12)	The DIR command with the /P switch generates a paper printout of the directory.
____ 13)	To move to a parent directory, you use the DIR command with “.” as an argument.
____ 14)	You can change from any directory on any drive to any directory on any other drive 
	using the CD command.
____ 15)	The FORMAT command will open with a menu interface if called with no 
	arguments.
____ 16)	The EDIT command has on-line help.
____ 17)	Typing in a command with the /? argument gives you HELP for that command.

Chapter 2 – The DOS File System

Understanding Disks

These days, there are several types of disks that your computer can use depending on the hardware you install. There are floppy disks, hard disks, CD ROMS, ZIP and JAZZ removable disks, Super Disks and so on. However, for the purpose of this discussion we will be dealing only with the floppy drive and the internal hard drive.
 
There are two common floppy disk drives in use today. The older type is the true “floppy” and is the 5 ¼ inch flat disk in a paper (sometimes flexible plastic) sleeve. This type of disk is almost extinct, but you still run into a few out in the field. The storage capacity of this type of drive started out at 180 Kbytes back in the 1980’s and ended up at 1.2 Mbytes for the last generations of these drives. The drive in common use today is the 3 ½ inch floppy which comes in a rigid plastic case with a movable shutter that covers the magnetic surface until the disk is inserted into the drive. These disks started at 720Kbytes and now are most commonly 1.44 Mbytes although there are some versions on the market that have a capacity of 2.88 Mbytes. As the capacity moved from 720K to 1.44 M, the disk itself changed. The magnetic surface was improved for the higher capacity. To keep people from being confused when buying the disks, the newer 1.44M disks have a square notch in the upper left corner. Again, the older 720K disks are almost impossible to fine, so there is no longer any confusion when buying disks. Note that even though the 1.2 M 5 ¼ and the 1.44 M 3 ½ disks hold almost the same amount of data, the size difference and the extra protection to the media offered by the 3 ½ disk has made it the clear survivor.

Take a look at one of your floppy disks. You will see that there is a hole on BOTH upper corners. The one on the right has a shutter that can be opened and closed. Look on the back of the disk and you can see the movable window. When the shutter is closed (can’t see through the hole) then the floppy can be written to. When the shutter is opened and looks like the hole on the other side, then the floppy is write protected. This means that any attempt to write to the disk, by you, a program or a virus, will fail. It is very important to “write protect” floppy disks that you wish to keep from being erased or overwritten. Examples are installation disks, boot disks and diagnostic disks. Once write protected, you can be sure that nothing will change the contents or infect it with a virus. The older 5 ¼ disks also have a write protect system. There is a notch cut out on the upper right side of the sleeve. When this notch is covered over with a peel-off tab, then the disk is write protected.

Getting a Disk Ready to Hold Data

The physical structures of the floppy disk are covered in more detail in class, but in a nutshell, the disks are formatted at the factory with 80 concentric tracks per side and then each track is divided into 18 sectors. Any sector can be accessed at random by the system, and a sector is the smallest part of a disk that can be read or written at a time. Each sector holds 512 bytes of data. Thus, 512 X 18 sectors per track X 80 tracks per side X 2 sides gives the 1474560 bytes (1.44 Mbytes) capacity of the disk. On the first track of the back side, the format allows for a sector that holds a boot program and boot information. There is a group of sectors that hold 2 copies of the FAT, and a bunch of sectors devoted to the root directory. The other sectors are for data. There are also hidden tracks on the disk that are accessible only by special utility and diagnostic software. These tracks can hold “unformat” information as described later.

A hard disk is very similar to a floppy in operation, especially from the point of view of the operating system. Physically, there is one additional sector at the start of the disk called a partition table. There are usually 2 or more platters in a hard drive and there are a LOT more tracks per platter and sectors per track. Also, modern hard drives have fewer sectors per track as the tracks move toward the center because the circumference of each track is smaller. Floppy disks are usually formatted and ready to use right out of the box. Hard disks are not. At the factory, hard disks are “low level” formatted which means they have the track and sector markings already written to the disk. However, they must be partitioned using the FDISK command and then high level formatted using the FORMAT command in the field to become functional. Hard drives should never need to be low level formatted in the field. Floppy disks are high level and low level formatted at the same time using FORMAT in the field and cannot be partitioned.

As mentioned in the last chapter, formatting prepares a disk to receive data by creating the boot sector, 2 copies of the FAT and the root directory. In the case of the floppy disk, it also creates the track and sector markings on the surface. Another thing FORMAT can do is check the surface of the disk for bad sectors and mark them as unusable. When FORMAT is called in its long form by using the /U switch, the entire disk is overwritten with test bytes to check the quality of the surface. However, the default action of FORMAT is to perform a “quick” format which verifies the readability of the disk surface only, doesn’t overwrite any of the data but clears the FAT and root directory so to the system it appears blank. At the end of the format process DOS assigns the disk a volume serial number and you are asked if you wish to add a volume label (name the disk). If so, enter a name of up to 11 character. Otherwise, hit ENTER and FORMAT will display a list of results including the amount of space and where it is being used and a total of any bad sectors.  The process also saves the FAT and root directory in a “mirror” file in a hidden area of the disk which allows the disk to be un-formatted in case the disk was formatted by accident. Un-formatting is successful providing no new data has been written to the disk. To do so, issue the command UNFORMAT with the drive letter as an argument.

As we have see already, you can pass the system files to a disk at the time of formatting to make it bootable using the /S switch. There are other switches for FORMAT that allow the formatting of odd-sized and old capacity disks. See the help for that command for details.

If at some time you wish to review the disk’s volume label, you can issue the internal command VOL with the drive letter as an argument. This volume information is also displayed when you issue the DIR command. According to DOS, you can use the LABEL command to display, delete or change the volume name. However, it doesn’t work. LABEL will display the name but if you attempt to delete it, it will “appear” to do so but will, in fact, not do it. Attempting to change the label results in an error message. Yes, DOS still has bugs.

Once a disk is formatted, we can store data on it in the form of files. These files can contain anything we choose be they programs, text documents, graphics, or some custom array of data you design yourself. To the computer it’s all the same. Any file on a disk is stored on groups of one or more sectors called “clusters” and has an entry in a directory pointing to the first cluster of the file. The rest of the clusters holding the file are cataloged in the FAT table. As far as the user is concerned, they need only know the file name and directory path to it. The rest of the work is behind the scenes.

EXERCISE # 6 – Formatting and Labels

1)	Be sure you are logged on to the root directory of drive C:
2)	Take your BOOT DISK floppy and place it into drive A:
3)	Issue the DIR  A: command and read the disk’s contents.
4)	Note the files on the disk and also the disk name. DIR will inform you that “This disk has no label”.
5)	Issue the FORMAT  A: command. Remember from last time how this command works.
6)	The disk will be “fast formatted” by default. Note at the start that FORMAT informs you that it is “Saving Un-Format Information”.
7)	When it is finished you will be asked to name the disk by giving it a label of up to 11 characters. Type in the label name EXERCISE 7.
8)	Issue the DIR  A: command. Note that there are no longer any files on the disk but it carries the EXERCISE 7 label.
9)	Issue the UNFORMAT command with A: as the argument. Inform the program that the disk in drive A: is to be un-formatted. Answer YES when prompted to be sure you want to unformat this disk with the “mirror” information it contains.
10)	When the command finishes, issue the DIR  A: command.
11)	Note that the disk is back to its original condition of being bootable and having no label.

Disk Maintenance

Most of the time there will be no need to perform maintenance on a disk. When those times do come, it can be very important to know how to perform it right. Your data may depend on it. There are two categories of disk maintenance and they apply generally to both hard drives and although to a lesser degree, floppies. The first of these categories is optimization. This includes defragmentation of the disk and routine scans of the file structures for minor problems. The DOS commands to carry out these functions are Disk Defragmentation (DEFRAG) and Scan Disk (SCANDISK). It is worth noting that third party software vendors create entire suites of programs to perform these and other maintenance functions and some of them are somewhat better than the versions included with DOS. However, the DOS versions are for the most part sufficient.

As files are stored on a disk and then deleted, the process creates storage holes on the disk. Small pockets of available space open up at random places when files are deleted, moved or re-written. Later, when you store new files on a disk, DOS tends to write the files starting with the first available cluster and then continues to select the next available cluster as more of each file is written to the disk. For very short files, this isn’t a problem but for longer files, DOS can end up storing fragments of that file all over the disk. This is called disk fragmentation. Reading these files can take much more time on a fragmented disk because DOS must wait on the drive as it moves the heads all over the place seeking these small fragments of data. Operations go much faster if all of a file is stored in sequential clusters so the heads need not move or must move only as far as the next track to continue reading a file. To speed data access, you will want to defragment the hard disk on a regular basis. How often depends on how much the system is used and how many files have been added, removed and/or appended in a given amount of time. As a rule, a business PC should be defragmented each week as part of a comprehensive maintenance policy; a home system maybe once per month. A floppy disk can also be defragmented, although this is seldom done or even necessary. 

Running the DOS “defragger” is very easy. Simply issue the command DEFRAG, and from the menu select the drive you wish to defragment and any special features you wish to add. You can also place the drive letter after the command as an argument and thus avoid the menu and run the program with the current default features. You can also add switches to the command line to select the features as well.

DOS Scan Disk is also good to run on a periodic basis. This program will check the drive for valid file names, proper boot sector data and test the FAT for invalid file chains or lost clusters. Lost clusters are those clusters counted as “used” in the FAT but are not really associated with any files currently in any directory. If desired, a test of the disk surface for errors can be run as well. In Exercise # 4 we looked at SCANDISK. This is a tool that might be run on a floppy disk as well as the hard disk.

The second category of disk maintenance is recovery. This is when you have a problem and need to repair damage to a file system. For the most part, if a disk is physically damaged, it’s toast! There is little if anything that can be done to recover data from a damaged disk. If, on the other hand, the data is corrupted or the file system is scrambled, there may be hope.

As a rule, the FDISK command is issued only to partition a new disk or re-partition an existing disk. In either case, any data on the disk is destroyed in the process. However, if the disk simply will not boot, there is an undocumented switch in the FDISK command that may help. Try issuing the FDISK /MRB command and this will re-construct the master boot record of the disk without destroying any of the data. Otherwise, issue and use the FDISK command only as a last resort and only when recovery of any existing data is either unnecessary or impossible.

If you accidentally re-format a disk or accidentally delete a file. You can use the UNFORMAT and UNDELETE commands to recover lost data. UNFORMAT recovers from a FORMAT and UNDELETE recovers from a DELETE. The important thing is to attempt recovery before writing again to that disk. Doing so can overwrite the data you’re trying to recover.

System Maintenance

There are two other DOS programs that are worth mentioning at this point. The first is the hard disk back-up program (MSBACKUP). It is very important to back up your hard disk on a regular basis. This is especially true if there is a lot of data on the disk that you have created such as documents, spreadsheets, music, graphics and so on. This material may be irreplaceable. Likewise, after spending so much time installing software and configuring your system to your liking, it would be a pain to have to re-do all of that in the event of a disk failure. Backing up the disk is the best protection against loss of data, time and productivity.

Due to the increasing threat computer viruses pose, and the ease with which your system can become infected, the DOS anti-virus program (MSAV) is a good one to know and use from time to time. This program tests memory, the boot sectors and files for the presents of known malevolent invasions. Viruses can exist not only in program files but also documents and email. Because the DOS anti-virus program is limited in the types of viruses it can detect, it is recommended that you eventually install a good third party anti-virus package on your system and keep its virus definitions updated.

EXERCISE # 7 – Maintenance

1)	Log on to the root directory of drive C: and from the DOS prompt, issue the command DEFRAG
2)	Select the C: drive and accept the default feature set. Begin the program by clicking on the OK button. The program will inform you that there is no need to defrag the drive because it is already 100% unfragmented. Ignore this advice and click OK.
3)	The program is designed to move data to a blank area of the disk to create space and then fill in that space with data that has been optimized. There is very little or no fragmented data on your disk at this point so the program will run very fast and make no changes.
4)	When the program is finished, exit back to the prompt.
5)	Have two blank floppy disks handy. Start the backup program by issuing the command MSBACKUP
6)	The program will detect that it has never been run and ask you to perform a compatibility test. Follow the instructions on the screen.
7)	As the test runs, a “script” will be executed simulating a user setting up a backup session and starting it running. The script runs very fast so don’t expect to catch everything. However, you will see how a user would use the mouse to select the files to back up, the place where the backup would be stored and so on. There will be times when the script will stop and wait for you to approve of what’s going on and click OK or hit ENTER. Stay awake and follow along. As the test progresses, you will be asked to insert the first blank floppy. After that disk is full, the computer will beep and ask you to change disks. Do this quickly, as part of this test is the ability of DOS to detect when you have changed disks without you having to hit ENTER. After the backup, you will be asked to re-insert the disks in proper order to perform the verify step. This is where the backup data is read from the floppies and compared to the original data to make sure the backup was successful.
8)	When finished, read the report MSBACKUP generates. As you exit MSBACKUP, you will need to select SAVE to save the test results and then exit back to the prompt.
9)	Start the anti-virus program running by issuing the MSAV command.
10)	Ask the program to perform a scan of the C: drive by selecting “DETECT”.
11)	After the scan is finished, you will see a report of the results. It should show that the memory and the contents of the C: drive were scanned with no viruses found.
12)	Return to the DOS prompt.
13)	Erase the 2 floppies MSBACKUP used by reformatting them. Use the command FORMAT  /U on each of the floppy disks to return them to a blank state.

Directories and Files

When we used the DIR command in chapter 1, we observed that we could display the contents of the root directory as well as the DOS directory. Now let’s take a closer look at what this display is telling us about our file system.

EXERCISE # 8 – Looking at File and Directory Information

1)	Make sure you are logged on to the root directory of drive C: and issue the command DIR with no parameters.
2)	Note that some entries are file names such as COMMAND.COM and AUTOEXEC.BAT. These entries are displayed with a file size in bytes and a date and time “stamp” which is the date and time this file was created or last modified.
3)	Look at the time stamp for COMMAND.COM and WINA20.386. Both say 6:22a which doesn’t mean that these files were created at 6:22 in the morning, but carry a stamp that identifies these files as belonging to DOS version 6.22. Often you will see software that carries some significant information about its version number in the time stamp of all files in the package instead of a real time of creation.
4)	Note the entry named DOS. It has no file size but a label that says <DIR> which means that this is not a file but the name of a sub-directory of which the current directory (in this case, the root) is the parent directory. Notice that the DOS directory entry also has a date and time stamp.
5)	Look at the last two lines that DIR displayed. The next-to-last line says that there are several files listed when you can see that only 4 of the items are really file names and the others are directory names. DOS calls all of them files. In fact, the physical entry in the directory for a sub-directory is basically the same as for a file entry. There are some structures that differ so DOS knows it can log on to DOS but not CONFIG.SYS.
6)	Also on that next-to-last line is a total size of all files in the directory. The bottom line now shows the total free space left on the drive.

As you recall, when we used the /W argument in the DIR command, it not only changed the arrangement on the screen but to save space eliminated all of the size and date information. However, often this information can help identify the nature of a file that is otherwise unfamiliar to you such as pointing out a DOS file by its 6:22a time stamp.

Now we’ll look at one of the mysteries of the DOS directory system. When you are logged on to a sub-directory of any kind; in other words, any directory other than the root, you will see two extra entries in the directory list right at the top. One will be named dot or “.” And the other dot-dot or “..” with a <DIR> tag beside each. The first entry is the current directory providing a space for itself and calling itself “dot”. The second is an entry for its parent directory and this is named “dot-dot”. As you recall, by issuing the command CD.. we can use the CD command to log on to the parent directory of any sub-directory. Here’s where those dots come from. Also, you will get no error message if you use the command CD. with only the one dot because this is just telling the system to log on to the directory where you already are. Not only is the directory list cluttered with these two strange entries but the total number of files at the bottom of the list will include these two entries in the count.

EXERCISE # 9 – Sub-directories

1)	Be sure you’re logged on to the root directory of drive C:.
2)	Create a new sub-directory with the Make Directory command using as an argument the name of the directory. Issue the command MD  TEST
3)	Log on to that directory with the command CD  TEST
4)	Now create another sub-directory off of this TEST sub-directory. Name it NEXT with the command MD NEXT.
5)	Issue the command CD\ to return to the root directory and then issue the command TREE. You now have a directory tree made up of the root with a child directory called TEST and it having a child directory called NEXT. 
6)	Log back on to the TEST directory with CD TEST. Issue the DIR command and look at the entries. You will see three. The first is the listing “dot” for the directory you are currently logged on to. The second is “dot-dot” for the parent directory and the last is the only “real” entry in the directory. It’s the entry for the sub-directory NEXT.
7)	As you can see, all of the date stamps are for a few moments ago when you created these directories. Even the “dot-dot” entry for the root is dated this way because the entry didn’t exist until the directory TEST was created.
8)	Note that the total used space is zero even though there are 2 “files” listed. This is because these entries are not really files at all but directory entries.
9)	Log on to the NEXT directory. Issue the DIR command and note the only entries are “dot” and “dot-dot”.

DOS Naming Conventions

We need to take a good look at file and directory naming conventions in DOS. While many of you may have used Windows 95 or 98 and gotten used to naming files anything you want, DOS doesn’t grant you that luxury. In fact, DOS has some very tight restrictions for naming. The convention is called the “Eight-dot-three” convention because the file name is split into two parts; a file name of at least one character but no more than eight characters and an optional extension of no more than three characters. The file name and extension are separated by a dot.  Also, a file or directory name under DOS can consist of only letters, numbers, and symbols OTHER THAN plus, equal, slash, back slash, colon, semicolon, bar, star, question mark, greater than, comma, period, quote marks, the space and the square brackets. Listed in print, these are the symbols you CANNOT use:
+ = / \ : ; | * ? > , . “ SPACE [ ]
and the rest are fair game but should be avoided to reduce confusion.

Most file names will have an extension after them. Most directory names will not. However, file names can have no extension and still be valid names, and directory names can have extensions. The main reason for the extension in file names is to categorize the files by function, type or parent program. Using generally agreed upon naming conventions, files can be grouped by extension into programs, batch files, documents, images, music, binary and so on. Because there is no “law” regarding the file extension, you or anyone else can name any sort of file any way you want regardless of the conventions like those mentioned above. However, it serves no purpose other than deliberate confusion to use an extension that is inappropriate for the file type. Also keep in mind that many applications will name files they generate with a specific extension that will generally identify the file as being the product of that application. Often an application will refuse to open a file that doesn’t have the specific extension it expects for that file type. This action of linking a file’s extension to a specific application or function is referred to as “association”. File association becomes more important in Windows where many automatic file activities are driven by file association.

EXERCISE # 10 – File Names

1)	Log on to the DOS directory.
2)	Execute a program that was included on the UTILITIES disk that you copied to your system. The command is DR
3)	This program will list the directory in a more user-friendly interface that allows you to scroll up and down the file list, move, copy, delete and rename files and sort the lists alphabetically or by extension.
4)	Hit the F8 key to sort the files by extension.
5)	Use the up and down arrow keys to scroll through the list of files. As you can see, there are many files with the .COM and .EXE extension. These are the programs that make up the DOS external commands. Also note several files with the .DLL extension. These files will be used by Windows 3.1 and are called Dynamic Linked Libraries. Also note several .SYS system files and .HLP help files.
6)	Using the arrow keys, place the highlight bar over the file name SYS.COM and hit the ENTER key.
7)	The DR program will display the contents of the file on the screen. As you can see, there is nothing there that a human can read. This file is made up of machine instructions. Hit ENTER again to go back to the file list.
8)	Move the highlight bar to the very last file listed which will be COUNTRY.TXT.
9)	Again, hit the ENTER key. As you can see this time, the file is formatted to be readable by people. This .TXT file is a text file and contains information about using DOS in countries other then the U.S.
10)	Hit ENTER again to return to the file list and then hit ESC to exit the DR program and return to the DOS prompt.

Wild Cards

Now comes the fun part. Suppose you want to check a directory for all files with a .SYS extension or all files whose names start with the letters JAN. You can use the DIR command and hunt through a directory for the files you want. You can also use a feature called “Wild cards” to format the DIR command to display only files that match your search criteria. Because the DOS DIR command doesn’t offer refinements like the DR command does, sorting out files can be a problem unless you use wild cards. There are two wild cards, the star “*” and the question mark “?”. To use the wild cards, you can replace any number of letters with the star or any one letter with the “?”. Using wild cards with the DIR command requires we take a look at one more feature of the command. You can offer DIR arguments other than directories and switches. You can also specify file names to be displayed. This will cause the command to show only those names in the directory list. It may not make much sense off hand to request a listing of files when you give a file’s name as an argument, such as DIR CONFIG.SYS when in the root directory. If you already knew that CONFIG.SYS was in the directory, why ask DOS to create a directory list showing only that one file. The real test of usability is when you DON’T know the name of the file you’re looking for or when you want to list only a particular type of file. Enter the wild cards.

With wild cards you can ask DIR to list a range of files all conforming to a specific criteria. For example, we will tell DIR to list all files with the .SYS extension by placing the “*” wild card in the place of the file name like this:
DIR  *.SYS
The “*” wild card can replace any and all letters in the name. In the above case, we basically said:
List “all file names”.SYS

The “*” can also be limited to replacing only those letters that come after a specific place in a file name. For example, if we wanted to list all files of extension .SYS with file names starting with DEV and followed by any other letters, we would use:
DIR  DEV*.SYS
And this would match files like DEV.SYS, DEVLOP.SYS, DEV1A.SYS, DEVELOP.SYS, DEVX.SYS and so on. As long at the file name started with the three letters DEV and had the extension .SYS, the file would be listed. Now suppose we wanted to list all files with the name TEMP regardless of the extension. This time we would use the wild card on the right side of the dot as shown:
DIR  TEMP.*
Note the fact that when using the * wildcard, any known parts of the file name must come BEFORE the * in either the name or extension. In other words, DEV*.SYS or NOV.B* are legal uses of the * wild card, but *DEV.SYS or NOV.*B are not.

As you might have guessed, we can list all files of all extensions by using:
DIR  *.*
Although this is a silly thing to do with the DIR command because by default it already lists all non-hidden files, there are situations where this will be very valuable such as when copying or deleting files.

The other wild card is the question mark “?”. It can also replace parts of a file name but only one character at a time. For example, if you wanted to list all files with file names ending with the letters TRC, you must use the “?” to replace the missing letters. The restriction is that you must know exactly how many letters the file name has so you know how many “?”s to add. In this case, we will assume that all file names will be six letters long. We replace the first three with ??? like so:
DIR  ???TRC.*
File names such as W13TRC.DOC, X21TRC.COM, WINTRC.386 will match. However, ABBSTRC.COM would not be listed because there are 4 characters before the TRC instead of 3 and so the ???TRC pattern wouldn’t have matched.

This wild card can also be used in the extension to hunt for specific files. To find all files with 3 character extensions ending in X, we would use:
DIR  *.??X
Note that the ? wild card can come at any place in a name or extension. Patterns like TM??.EXE, SON??BT.BAT, LIST.T?P and ???D???A.?P? are all equally legal uses of the ? wild card.

At this stage you might question the functionality of wild cards. However, With the introduction of the next group of DOS commands, that functionality will become clear.

EXERCISE # 11 – Wild Cards

1)	Log on to the DOS directory.
2)	Issue the DIR command with the /P switch.
3)	Page through the list of file names and get a general idea of how many pages full there are.
4)	Issue the command again but using wild cards to filter files by type. Issue the command as DIR  *.EXE  /P and see how many pages you get.
5)	As you can see, only the .EXE files are listed.
6)	Try it again but this time with the wild card in the extension to filter names only. Issue the command DIR  COMMAND.* without the /P.
7)	Only 1 file fits that search criteria.
8)	Let’s try it now using the “?” wild card.
9)	Issue the command DIR  *.??T to get all files with a three-character extension ending in the letter T. Note from the date stamps that 2 of them were created when you ran MSBACKUP.
10)	Try DIR ???E.* and see how many files you get.

Working With File Trees

There is another very useful command that DOS provides for gaining an overview of the directory structure on a disk or some part of a disk. It is the command TREE. We used it a few exercises ago to see the directory structure of the hard drive after creating the TEST and NEXT directory tree. As you saw, by issuing this command you will get a graphical listing of all directories and their subdirectories beginning at the location given to the command as an argument, or starting at the current default directory if none is given. By using the /F switch, you can make this command even more powerful by having it list all of the files in all of those directories as well. The problem with using this switch is that the list can become rather long. If you remember when using the DIR command on the DOS directory, there were so many files that they scrolled off the screen before you could read them. We had to use the /P switch to force DIR to list files one screen-full at a time. The TREE command has no /P switch and therefore no direct way to slow it down to a screen-full at a time. There is, however, another way. DOS provides a system for taking the output, or results of one command and using these results as the input for other commands. This is called “Piping” because you are placing multiple DOS commands in a “pipe” such that the output of the first is fed to the input of the next. This technique can be done with many DOS commands but we will begin our discussion of piping with this example.

We are going to take the output of the TREE command and pipe it into another command called MORE. The MORE command is a “/P switch in a box” so to speak. It will take whatever is fed to it and will display it to the screen one screen-full at a time and wait for the user to hit a key before displaying the next screen-full, just like DIR does when using the /P switch. The way it works is that the pipe symbol is used on the command line between the DOS commands that will be fed to/from it. This causes DOS to take the output of the first command, in this case the TREE command, and convert it into a temporary file on the disk. Once that first command has ended, DOS then takes this file and starts the next command, the MORE command, using that file as a built-in argument. Thus, the next command inputs the file and processes it. If there is another pipe symbol, then this file’s results are stored in a temporary file until the command is finished and then those results are fed to the next command and so on for as many commands are being piped together. The pipe symbol is on the key showing a vertical bar above the backslash and is entered by hitting SHIFT and then BACKSLASH.

There are many other commands that can be piped through MORE to tame the display. Also, other commands besides MORE can be used to process the outputs of other DOS commands. Many DOS commands may be piped through many other DOS commands.

EXERCISE # 12 – Using TREE and the Pipe to MORE

1)	Log on to the root directory of drive C:
2)	Issue the TREE command.
3)	At this point in the life of your PC, there isn’t much on your system in the way of a tree structure. However, you can see how the TREE command will draw a chart of your directories and show the hierarchical relationships of directories to subdirectories.
4)	Now issue the command as TREE  /F to get a listing of the directories along with the files they contain. As you can see, the list shoots past far to quickly to be of any value.
5)	Now try the command as piped through the MORE command. Issue the command TREE  /F  |  MORE
6)	There will be a pause while TREE generates its output and stores it in a file for MORE to read and process. After the delay, you will see the output of the MORE command which is the page formatted output of the TREE command.

Terminating a DOS Command

There may be times when you will want to stop DOS from finishing the execution of a command. Most of the time, they will execute so quickly that you couldn’t stop them fast enough even if you tried. However, there are the cases when DOS is paused and waiting for something to happen where you can sneak in and terminate the command. The best example is when listing a long directory with the DIR /P command. DOS has displayed a page full of files and as you hit a key and view page after page, you finely get to the page containing the file you’re looking for. Now suppose that there are several more pages left to display before the command exits but you see no need to keep hitting keys to scroll through them. You can hit the CTRL key and then the “C” key to cause DOS to abort right then and there. This is also possible when stopped between pages with the MORE command or any other command that is running along at a pace such that you have time to stop it before it’s done. File copy and delete jobs, formatting, and so on are other examples where you may find a need to force DOS to abort before the normal end of command execution.

EXERCISE # 13 – Aborting DOS

1)	Make sure you’re logged on to the root directory.
2)	Issue the command DIR  C:\DOS  /P
3)	After the first page of file names, hit a key to see another page.
4)	Now let’s assume you’ve seen all you want to see and wish to abort the command.
5)	Hold the CTRL key and hit the “C” key and you're back to the DOS prompt.
6)	Issue the command TREE  /F  |  MORE and again, you are in a situation where you may wish to abort out of this command after finding what you’re looking for early on.
7)	Hold the CTRL key and hit the “C” key and abort from the DOS command.

CHAPTER 2 QUIZ: Answer T for True and F for False.

____ 1)	Besides the size of the disk the main difference between the 3 ½” and 5 ¼” floppy is
	the fact that the 3 ½” disk holds 60% more data.
____ 2)	The window in the top right corner of a 3 ½” disk has a shutter that can be opened to
	prevent the disk from being written to.
____ 3)	The other window in the upper left corner of a 3 ½” disk is to prevent a disk from 
	being infected with a virus.
____ 4)	A 1.44 Mbyte floppy has 80 tracks, 40 on each side.
____ 5)	FDISK is used to partition a hard disk.
____ 6)	You must partition a floppy disk like a hard disk except you use FORMAT to 
	partition a floppy disk.
____ 7)	Using the /S argument with FORMAT will make a disk bootable.
____ 8)	Running DEFRAG will correct some simple errors on the disk such as lost clusters.
____ 9)	You can use the UNDELETE command to recover from an accidental format so long 
	as you haven’t written anything new to the disk.
____ 10)	A file’s time stamp can only be used to show the time of day when the file was created 
	or last changed.
____ 11)	To return to the parent directory, we use CD.. and can use CD… to move to the parent 
	of the parent directory.
____ 12)	You can also create new directories with the CD command.
____ 13)	All DOS file names must have an extension of from 1 to 3 characters.
____ 14)	You can list all files with TMP in the file name by using the DIR command and 
	putting a “*” wild card followed by the letters TMP then a dot and another “*” wild 
	card.
____ 15)	 The command DIR  ???.COM will list only files having three letters in the file name 
	and an extension of .COM.
____ 16)	By default (meaning without using any switches with the command), the TREE
	command will generate a graphical representation of the 	directory structure always 
	starting at the root directory even if you’re logged on to a different directory.
____ 17	You can use the CTRL “C” key combination to abort from the MORE pipe.

Chapter 3 – Working With Files

File Copying

An operating system wouldn’t be of much use if it didn’t have tools for manipulating files. Some of the actions that we might want to perform on files include sorting, copying, moving, deleting, renaming and even creating. The sorting part can be performed with the DIR command using the switches that sort the file list by name, date, extension, etc and/or using wild cards. The rest of these functions can be performed with other DOS commands.

The most common action is file copying. There are 2 DOS commands made to copy files. The internal command is COPY and the external command is the somewhat more powerful XCOPY.
Either command will copy a file from a source location to a destination. There must be arguments passed to these commands to tell them what to copy and where to put it. First, you would list the file or files to copy as the source. This is where wild cards come in real handy. By default, as is the case with most DOS commands, if no source path is specified with the file names it is assumed that the source is the current default directory (the directory you are logged on ti). The same applies to the destination. If no destination is given, DOS will copy the files to the current directory you are logged on to. If you specify only a directory as the destination, then DOS will copy the files to that location. If you specify a destination file name as well as directory, DOS will change the file names as it copies them. You cannot specify the same location as both source and destination unless you offer a new destination file name. In other words, DOS will not allow you to copy files back to the same place unless you are renaming them in the process. In that case, you will end up with both the original files and the new renamed copies in the same directory.

There are several switches that can be set with either COPY or XCOPY. The XCOPY is much more powerful than COPY and can, among other things, copy entire directories and sub-directories in one operation. Both support the /V switch, and it is recommended that you use this switch whenever copying to floppy. The /V switch asks DOS to verify the copied files to make sure they were copied correctly. Nothing is more disappointing than copying files to a floppy, going half-way across the country and then discovering the files didn’t copy correctly. Actually, the verify feature doesn’t do a byte-for-byte compare of the source and destination data. It simply reads the destination sectors to be sure each sector is valid. In practice, this is about 99.9999% effective in assuring that the data was copied correctly. If you want to do a real compare, there is the FC command which will do that byte-for-byte compare.

EXERCISE # 14 – File Copying

1)	Log on to the DOS directory.
2)	Issue the command COPY  README.TXT  C:\TEST to copy the file README.TXT from the DOS directory to the TEST directory.
3)	Issue the command DIR  C:\TEST and verify that the file was copied.
4)	Now issue the command COPY  README.TXT  C:\TEST\TEST.TXT to both copy the file but rename it at the destination.
5)	Issue the command DIR  C:\TEST to verify the copy took place.
6)	Issue the command FC  C:\TEST\README.TXT  C:\TEST\TEST.TXT and prove that the files are identical.
7)	Issue the command COPY  *.COM  C:\TEST to copy all .COM files to the TEST directory.
8)	Issue the command DIR  C:\TEST to see the results.
9)	Issue the command COPY  DRVSPACE.?X?  C:\TEST\NEXT and copy some files to that directory.
10)	Issue the DIR  C:\TEST\NEXT command and look at the results.
11)	Put a blank floppy in drive A:
12)	Issue the command XCOPY C:\TEST\*.*  A: /S  to copy all files from the TEST directory to the floppy including its subdirectory NEXT and its contents.
13)	With the command DIR  A:  /S  /W to display the contents of the A drive including the subdirectory NEXT and its contents too, in a wide format so everything will fit on one screen.

Moving, Renaming and Deleting Files

There is another way of renaming files. The DOS Rename command (RENAME or REN) is used to simply change file names without moving them or copying them. However, this command cannot rename directories. To do that, you must use the MOVE command. Sound confusing? Tell that to Bill Gates.

The MOVE command is mostly used to copy a file to a new location and then delete the original at the source location so it has the effect of “moving” the file from one place to another. This command will also benefit from the use of wild cards when operating on groups of files with some aspect of their name or extension in common. As mentioned above, the MOVE command will also rename a file during the move if the destination path includes a new file name. Renaming directories is possible with this command by attempting to “move” the directory to itself with a different name.

At some point you will need to delete files or groups of files from your disks. DOS makes this easy with the DEL or ERASE commands. These two commands are really different names for the identical command. They work as you might expect by requiring the name of the files to delete and wild cards come in real handy. This command will not erase a directory, however. There is a command called RD that will remove directories providing they are empty.

EXERCISE # 15 – More File Operations

1)	Log on to the TEST directory.
2)	Issue the DIR command to review the contents this directory.
3)	Try renaming EDIT.COM to TYPER.EXE by using the RENAME command. Issue the command  REN  EDIT.COM  TYPER.EXE
4)	Issue the DIR command again and look for this new file name.
5)	Prove that it is still the same file by running it. Issue the command TYPER
6)	As you can see, the good old EDIT screen appears. The program is the same, only the file name and extension have been changed.
7)	Remember, if a file ends in either .COM or .EXE then DOS expects the file to be an executable program. In the above example, TYPER executed just like EDIT because DOS treats .COM and .EXE files the same way.
8)	Change the name again by issuing the command REN  TYPER.EXE  JUNK.MTV
9)	Now try to execute the command JUNK
10)	As you can see, there is no way DOS will execute the file because it doesn’t recognize the .MTV extension as an executable file type.
11)	Issue the command REN  JUNK.MTV  JUNK.COM
12)	Now execute the command JUNK
13)	The file once again executes.
14)	Now we will move this file. Issue the command MOVE  JUNK.COM  C:\TEST\NEXT
15)	Issue the DIR command and see that JUNK.COM is no longer in your TEST directory.
16)	Issue CD  NEXT to change to the NEXT directory.
17)	Using the DIR command, verify that the file now appears in this directory.
18)	Issue the command MOVE  *.*  C:\TEST and move all of the files from this directory to the TEST directory.
19)	Issue the DIR command and verify that this directory is now empty.
20)	Log back on to the TEST directory using CD..
21)	With the DIR command, verify that these files are now located here.
22)	Issue the command MOVE  *.TXT  C:\TEST\NEXT and move all .TXT files from the TEST directory to the NEXT directory.
23)	Now use the MOVE command to rename the NEXT directory to HOLD. Issue the command MOVE  NEXT  HOLD
24)	With the DIR command look at the result. There is no longer a NEXT subdirectory but a HOLD subdirectory.
25)	Log on to this directory using CD HOLD and then with the DIR command see the .TXT files we moved to the NEXT directory are now in a directory called HOLD.
26)	Delete the file TEST.TXT with the command DEL  TEST.TXT
27)	Using the DIR command see that this file no longer exists.
28)	Now issue the command DEL  *.TXT and then see with the DIR command that this directory is now empty because all files with the  .TXT extension were erased.
29)	Log back on to the TEST directory using CD..
30)	Issue the command RD  HOLD and delete the subdirectory.
31)	With the DIR command, verify that there is no longer a subdirectory listed in the contents of the TEST directory.
32)	Log on to the root directory using CD\
33)	Issue the command RD TEST
34)	As you can see, DOS refused to delete the directory because it isn’t empty.
35)	Issue the command DEL  C:\TEST\*.* to remove all files from the TEST directory. Notice that DOS will warn you this is about to take place and asks for your conformation.
36)	Now issue the command RD  TEST
37)	Issue the DIR command from the root directory and see that there is no longer a TEST directory on your hard drive.

Bulk Deletion

If you wish to delete the entire contents of a directory including all subdirectories and their contents, there is a command to do this. It is a very powerful command and extremely dangerous.
It is the DELTREE command. As the name implies, it is designed to delete an entire directory tree in one operation. Don’t issue this command without thinking through the results. Undeleting an entire tree that you have mistakenly wiped out with DELTREE is an enormous pain in the butt! Unlike the RD command, DELTREE will delete directories containing files. Also, unlike the DELETE command, DELTREE will delete hidden, system and read-only files. However, DELTREE will not effect a directory you are logged on to. When deleting a tree, you cannot be logged on to a directory that is part of that tree you are trying to delete.

EXERCISE # 16 – Using DELTREE
1)	Log on to the root directory of drive C:
2)	Make some directories. Start by issuing MD  FIRST
3)	Using CD  FIRST log on to the FIRST directory and issue MD  SEC1
4)	Make a few more subdirectories in FIRST with MD  SEC2 and MD  SEC3
5)	Log on to SEC1 and issue MD  THIRD
6)	With CD.. go back to FIRST and then log on to SEC2 with CD  SEC2
7)	Use MD THIRD1 and MD THIRD2 commands to create some subdirectories off of SEC2.
8)	Log on to THIRD2  using CD  THIRD2 and issue MD  FORTH
9)	Now log on to the DOS directory using CD  C:\DOS
10)	Lets see our new directory tree. Issue the command TREE  C:\FIRST
11)	Now we’ll put some files in our tree. Issue the command COPY  *.TXT  C:\FIRST
12)	Issue the command COPY  *.HLP  C:\FIRST\SEC1
13)	Issue the command COPY  D*.COM  C:\FIRST\SEC2
14)	Issue the command COPY  *.DLL C:\FIRST\SEC3
15)	Issue the command COPY  *.INI  C:\FIRST\SEC1\THIRD
16)	Issue the command COPY  *.CPI  C:\FIRST\SEC2\THIRD1
17)	Issue the command COPY *.386  C:\FIRST\SEC2\THIRD2
18)	Issue the command COPY *.SYS  C:\FIRST\SEC2\THIRD2\FORTH
19)	Now take a look at this tree using TREE  C:\FIRST  /F  |  MORE
20)	A lot of files have ended up in this tree. Let’s wipe the whole thing out in one operation. Issue the command DELTREE  C:\FIRST
21)	Log on to the root directory with CD.. and issue the DIR command. As you can see, there is no longer any trace of the directory FIRST and thus no trace of its contents, subdirectories or their contents.

File Attributes

In the older UNIX operating system, files are given a wide range of attributes and permissions that dictate how the file can be used and by whom. In DOS, that list of attributes was reduced to only four. A file can be marked as being read-only, a system file, a hidden file or a file that must be backed-up. This doesn’t offer as much security as UNIX which can also dictate which users have permission to read a file or execute a program, but it’s what we have to work with.

In the directory entry for all files, there are attributes stored along with the file name and size and so forth. Sub-directories also have attributes but these aren’t used as often. Attributes offer some limited security. For example, one attribute will render the file read-only and prevent the file from being deleted, appended or otherwise altered without taking special steps to overcome the protection. Another attribute will tag a file as being a “system” file thus preventing it from being  copied by XCOPY. The “hidden” attribute will prevent a DIR command from listing these files. The “archive” attribute will flag files that have been created or changed sense the last back-up.

In order to perform some operations on certain files, you must add a switch to a command in order to allow that command to access the file or you may need to alter the attributes of the file directly. For example, the DIR command will not list hidden files by default. However, adding the /A:H switch, DIR will list only the hidden files.  Also, XCOPY will not copy hidden or system files at all, so the ATTRIB command must be run on those files to give XCOPY access to them.
The ATTRIB command allows you to set or reset the attributes of a file. If you have a hidden file that you need to copy, you can unhide it, copy it and then re-hide it. If you need to delete a read-only file, you must use ATTRIB to remove its read-only status to make it easily deleteable.

EXERCISE # 17 – File Attributes

1)	Log on to the root directory of drive C:
2)	The DR utility will display hidden files easily. Issue the command DR and look at the files in the root directory. Look at the end of the lines containing the file names in the DR list. These are the attributes of the files and are abbreviated H for hidden, S for system, R for read-only and A for archive. The files IO.SYS and MSDOS.SYS are hidden, system and read-only. The file COMMAND.COM is read-only. The rest of the files all show that they have not been backed-up by displaying an A. Hit ESC to exit the DR program.
3)	From the root directory, create a new sub-directory. Issue the command MD  ATTR
4)	Use the XCOPY to copy the files in the root directory to the ATTR directory by issuing the command XCOPY  *.*  C:\ATTR
5)	Log on to the ATTR directory with CD  ATTR and remain logged on to it.
6)	Issue DR again. Notice that the hidden system files IO.SYS and MSDOS.SYS were not copied. Also note that COMMAND.COM was copied but is no longer read-only like it was in the root directory but shows an A meaning that it will need to be backed-up now that it has appeared in a new location. Hit ESC to exit DR.
7)	Issue the DIR command to prove that all of these files will list.
8)	Let’s mess with the attributes of these files. First, we’ll make AUTOEXEC.BAT a read-only file. Issue the command ATTRIB  +R  AUTOEXEC.BAT 
9)	make COMMAND.COM a hidden file with ATTRIB  +H  COMMAND.COM
10)	Make CONFIG.SYS a system file with ATTRIB  +S  CONFIG.SYS
11)	Run the DR utility and look at the attributes of the files we changed. Hit ESC to exit.
12)	Issue the command DIR to see that COMMAND.COM is no longer listed because it’s now a hidden file.
13)	Issue the command DEL AUTOEXEC.BAT but expect the command to fail because you cannot delete a read-only file.
14)	Create a sub-directory off of the ATTR directory by issuing the command MD NEW
15)	Issue the command XCOPY  *.*  C:\ATTR\NEW
16)	Issue the command DR  NEW  and take a look at what was copied to the NEW directory.
17)	As you can see, COMMAND.COM and CONFIG.SYS were left out of the copy because of their new attributes.
18)	Log on to the root directory with the command CD\
19)	Remove this test directory tree with the command DELTREE  C:\ATTR
20)	Notice that the fact that this tree contained hidden, system and read-only file didn’t deter DELTREE from erasing them or the directories containing them.

File Input and Output

Although in this lab you have no access to a printer, we need to take a moment to review some of the DOS commands that relate to printing. We have no way of producing exercises on this topic so we will simply have to discuss the topic and then move on.

There are three common methods of printing in DOS. The first and easiest is using the PRINT SCREEN key located at the top of the keyboard on the right side. Hitting this key will cause the current contents of the display to go to the printer. This key can sometimes become disabled by an application, so you can’t relay on using it under all conditions. However, to spool the text on the screen to a printer while working in DOS and most non-graphical applications, you need only hit this key.

Another way of printing data is to use the PRINT command. This command prints files and will take as arguments the names of files to be printed. You can also specify the port where the printer you wish to use is located. By default, this will be the first parallel port called LPT1 or the “printer port”. In DOS, this port is often referred to as “PRN”. The PRINT command will work in the “background” which means that you can go on and do other things while DOS prints your files. This is a big improvement over older versions of DOS which used to tie up the computer until printing was finished. There are several switches you can use with this command. They involve setting the number of clock ticks that DOS is willing to wait for printer response and how much time DOS should share between printing and the other things you may be trying to do at the same time. Other switches allow you to add or remove files after printing has already started. This is referred to as adding or removing jobs from the print queue. Also, you can issue the command with no arguments to install the program into memory without running it and also get a status report on the currently running print jobs, if any. The best idea in this situation of having no printer to test this command with is to issue the HELP command and look up the PRINT command so you can read up on it.

The last method of printing that we’re going to discuss is the use of the redirect symbol. This symbol is sort of like using piping. As a rule, DOS directs the input and output of commands to a default device called the “console” which is the keyboard for input and the display for output. However, you can persuade DOS into redirecting the output of a command from the usual console display to, for example, the printer. If you wanted to get a print-out of the contents of a directory, you could issue the DIR command and redirect the output to the printer. The output redirect symbol is the “>” symbol and is places between the command to be redirected and the location where the output is to be sent. In the above example, the command would be issued like this:
DIR > PRN
The result will be a printout at the default printer of the directory listing DIR would have otherwise sent to the screen. Be advised that the redirect will do exactly that. There will be no display on screen if the output of a command is redirected elsewhere.

Using Output Redirection

As it turns out, the redirection of output is not limited to a printer. Output can be redirected to a COM port or even to a file. In the case of a file, you must give a file name and also a path if you want to store the output in a file not in the current default directory. If the file doesn’t exist, it’s created and filled with the output of the command being redirected. If the file already exists, the contents will be deleted and replaces with the redirected output. If you want to sent output to an existing file without erasing the current contents, use a pair of redirect symbols like “>>” and this will append the output to the end of the existing file instead of replace it. Again, if the file doesn’t yet exist, the “>>” redirect will create it just like the “>” redirect will.

EXERCISE # 18 – Redirecting Output

1)	Log on to the root directory.
2)	Issue the command DIR  C:\DOS and see how you need to use the /P switch to see the results or somehow find some way to capture the resulting list.
3)	First try the command’s built-in technique. Issuing the command DIR  C:\DOS  /P
4)	Now try the way we did it in exercise # 13 by issuing the command with the pipe into MORE like DIR  C:\DOS  |  MORE
5)	Now suppose you wanted not only to slow down the display but also to record the results of the command. The best way to do this is use the redirect function to save the output in a file. We will call the file DIRLIST.TXT and save it in the TEMP directory.
6)	Issue the command DIR  C:\DOS  >  C:\TEMP\DIRLIST.TXT to send the output of the DIR command to a text file.
7)	To see this text file, issue the command TYPE  C:\TEMP\DIRLIST.TXT 
8)	Again, you now have a paging problem. Let’s try a different approach. Issue the command EDIT C:\TEMP\DIRLIST.TXT and open the file in the DOS editor.
9)	Now we can view the file by scrolling up and down the screen using the PAGE UP and PAGE DOWN keys as well as the mouse and scroll bars. Also, because this copy of the directory list is a file, you can edit it, cut and paste sections of it move parts into other documents, print it and so on. Close the editor by holding down the ALT key and hitting the “F” key to open the FILE menu (or click on the FILE button at the top of the screen with the mouse) and hit the “X” key to exit (or click on the EXIT menu item). If you made any changes to the file, select NO to the prompt to save changes.
10)	As an alternative to the EDIT command, use the utility we installed earlier by issuing the command DR  C:\TEMP
11)	Move the highlight bar over the file DIRLIST.TXT if it isn’t already, and hit the ENTER key. Although you can’t edit from this screen, you can at least view the file any time you need to reference this list. Hit ESC to leave the file viewer and then hit ESC again to exit the program DR.
12)	Now let’s try it again. Issue the command DIR  >  C:\TEMP\DIRLIST.TXT
13)	Now view the file with the command DR  C:\TEMP, highlight the file DIRLIST.TXT and hit ENTER.
14)	It seems that the previous contents are gone and have been replaced by this list of the root directory. What if you had wanted both directory lists to be present? Exit DR by hitting ESC twice.
15)	Issue the command DIR  C:\DOS >> C:\TEMP\DIRLIST.TXT and this time use the double “>>” redirect symbol.
16)	Open the file using DR  C:\TEMP, highlighting and hitting ENTER. This time the previous contents weren’t replaced but the new listing of the DOS directory was added to, or “appended” to the listing for the root directory. Exit the DR program.

Using Input Redirection

Redirecting input works the same way. In this case, you use the “<” symbol. This allows you to use the contents of a file as the input of a command. The MORE command can be used this way as well as by piping the output of one command into the input of MORE. 

EXERCISE # 19 – Using MORE and Input Redirection

1)	From any directory, issue the command TYPE  C:\TEMP\DIRLIST.TXT and notice how the file is too large to view without some sort of screen formatting.
2)	Let’s try the MORE command with the pipe like we learned in earlier exercises. Issue the command TYPE  C:\TEMP\DIRLIST.TXT  |  MORE
3)	That works well enough. Now we’ll do the same thing with MORE except using the input redirect. Issue the command MORE  <  C:\TEMP\DIRLIST.TXT
4)	As you can see, the results are the same as when we used the pipe. This shows how the input redirect will allow a file to become the input of a DOS command.

Sorting in Files

To make the concept of input redirect a bit clearer, let’s introduce some new DOS commands and learn how to use them with files as their inputs. First we’ll look at SORT. This command will take the output of another command through a pipe or the contents of a file through input redirection and sort the text line by line alphabetically. The command has switches that allow you to sort by column and also to reverse the order of the sort. When using the pipe, you can take the output of another command and send it to SORT. With input redirection, you can send a file through SORT. In either case, you can send the results to the screen or use output redirect to write the results to a file. If sending to the screen, you can also further pipe the output through MORE to control the display.

EXERCISE # 20 – Using SORT

1)	Log on to the root directory of drive C:
2)	Let’s sort the directory list that we created and stored in the file DIRLIST.TXT. Issue the command SORT  <  C:\TEMP\DIRLIST.TXT
3)	Oops! We need a way of controlling the display. Let’s add the pipe and send the output through MORE like this: SORT  < C:\TEMP\DIRLIST.TXT  |  MORE
4)	That worked better. Now we need a permanent copy of the results. Let’s sent the results to a file. SORT  < C:\TEMP\DIRLIST.TXT  >  C:\TEMP\SORT.TXT should do the job.
5)	Let’s look at this file using TYPE  C:\TEMP\SORT.TXT  |  MORE
6)	That was interesting. Now we’ll sort the items backwards from Z to A. Issue the command SORT  /R  < C:\TEMP\DIRLIST.TXT  |  MORE
7)	Looks good. However, we could have done this directly with the DIR command. Let’s try DIR  C:\DOS  | SORT  /R  | MORE 
8)	In this example, we made a pipe three commands long. First we created a directory list of the DOS directory, then piped the list through SORT and sorted that list from Z to A and finely piped the result through MORE to control the display.
9)	Try issuing DIR  C:\DOS  |  SORT  /R  >>  C:\TEMP\SORT.TXT
10)	View the results using TYPE  C:\TEMP\DIRLIST.TXT  |  MORE
11)	Because we used the “>>” redirect for our output, we appended that last sort to the end of the original DIRLIST.TXT file. Now this file contains the list made by the DIR command followed by a backward-sorted version of the same information.

The DOS Console

If you recall, the output redirection can send output to a device like the printer as well as to a file. The same is true for redirecting input. The source of a command can be not only a file but a device. Examples would be a modem, a tape drive and the most common, the keyboard. We can create files using the COPY command and CON to input the text of the file from the keyboard. The DOS location for the keyboard is CON which is short for console. The console is an old term dating back to the days of remote terminals that consisted of a keyboard, a monitor and only enough logic to communicate to a remote mainframe. Today this term survives as CON. Incidentally, DOS commands that send their output to other commands or to files can be told to send that information to the display instead by redirecting output to CON, although this function is extremely obscure.

EXERCISE # 21 – Using CON

1)	First, see how we can print a file to the display using CON. Log on to the root directory of drive C: and issue the command COPY  AUTOEXEC.BAT  CON
2)	As you can see, this copied the file from the source (AUTOEXEC.BAT) to the destination (CON). Also you get the usual statistical line informing you that one file was copied.
3)	Create a new file by issuing the command COPY  CON C:\TEMP\STUFF.TXT
4)	As soon as you hit ENTER, the cursor dropped down a line and just blinked. There is no prompt any more. DOS is waiting for you to type in the contents of your file. Type in the following: This is a test of the CON function and the COPY command.
5)	Now hit the ENTER key to bring the cursor down to the next line. Type in: Redirection can be done using the pipe also.
6)	Hit ENTER again. Now signal DOS that you’re finished by issuing the END OF FILE marker. Hold the CTRL key and hit the “Z” key. Now hit ENTER..
7)	You are again informed that one file was copied and the prompt returns.
8)	View the new file by issuing the command COPY  C:\TEMP\STUFF.TXT  CON

Echoing Text

Just for the record, there is another way to create a file from the keyboard using redirection. There is a DOS command called ECHO which is usually used in batch files to print to the screen. However, you can use ECHO and the output redirect symbol to print to the printer or a file. This can come in handy if you are trying to troubleshoot a printer and need to send text to it from time to time from the command line. Also, this technique allows you to add headers, titles or separators to files created by redirecting other commands.

EXERCISE # 22 – Redirecting ECHO

1)	Make sure you’re logged on to the root directory of drive C:
2)	Issue the command ECHO Directory List  >  C:\TEMP\LIST.TXT
3)	Look at the result with  TYPE  C:\TEMP\LIST.TXT
4)	Now add something to that file. First, we add another blank line. Issue the command ECHO. >> C:\TEMP\LIST.TXT (DON’T FORGET THE PERIOD AFTER “ECHO”) and this will append the file with another new line character.
5)	Now send a directory list to the file with DIR  >>  C:\TEMP\LIST.TXT
6)	Next add a separator with ECHO.  >>  C:\TEMP\LIST.TXT and then add a new header with ECHO Sorted List  >>  C:\TEMP\LIST.TXT and finely another blank line with ECHO.  >>  C:\TEMP\LIST.TXT
7)	Add another list of the root directory but this time, sorted alphabetically. Issue the command DIR  |  SORT  >>  C:\TEMP\LIST.TXT
8)	View the result with the command EDIT C:\TEMP\LIST.TXT
9)	Scroll through the text in the editor and notice all of the elements you added. Exit the editor back to the prompt.

Using FIND

The input redirect function and the pipe function are related and most commands that use the first can also use the second. As another example, let’s look at the FIND command. This command will search an input source, usually a file, for some specified text content and if found, displays it to the screen. As you might expect, the output can also be redirected to a file. However, this is an example where input redirection isn’t necessary because the command is designed to receive the names of the files to search as arguments. It will respond to piping as usual, though. To use the command, you list on the command line the text string you are searching for enclosed in quote marks, the name of the file to search and you can also use switches that will display line numbers, total occurrences of the string in the file, only the lines that do NOT contain the string and also a switch to ignore the case of the text. The most common usage of the FIND command is to offer the command several file names as arguments to see which one of them contains the text string in question. The one very disappointing thing about this command is its inability to use wild cards in the list of files it is to search. Instead of being able to us the command like FIND “SOME TEXT” *.TXT you must write out the full names of each file you intend to search through. Needless to say, this isn’t a very popular command for doing intensive searches through large groups of files.

EXERCISE # 23 – Using the FIND command

1)	Suppose you need to search through the text documents supplied with DOS to find references to running the program MemMaker. However, you can’t remember which file contained the information you’re looking for so you must search through several of them.
2)	Log on to the DOS directory.
3)	Issue the command FIND “MemMaker” readme.txt networks.txt country.txt being sure to use the exact letter case shown for the text in quotes.
4)	It looks like there are a lot of references to MemMaker in some of these files but you need to control the display. Hit the F3 key and DOS will place the command you just typed back on the command line.
5)	This time, add the pipe through MORE and try it again.
6)	You will get a full screen of lines from README.TXT that contain the term MemMaker. Hit a key and you will get a second screen. There are more lines from README.TXT displayed as well as a few lines from NETWORKS.TXT containing references to MemMaker. However, you will notice that there were no references in the file COUNTRY.TXT

DOS Command Memory and DOSKEY

In the above exercise we not only looked at the FIND command but also made reference to one of the DOS command line control keys. DOS remembers the last command you issued and will replace it back on the command line for you if you hit the F3 key. There are also other things you can do with the stored command. If you hit the F1 key, for example, you can recall the previous command character by character. These other functions are, in practice, of limited use. You can only recall the most recent command and if you want to edit that command you must backspace through it erasing characters as you go. This is a real pain if all you need to do is insert a character or correct a simple typo at the beginning of the command. There is, however, a DOS command that allows you to keep and recall an entire history of commands and also allows you to move the cursor non-destructively to any point in the command line and edit its contents. This command is DOSKEY. When you issue this command, you tell DOS to set aside a section of memory to hold all of the commands you issue so you can page through them later and recall any of them to issue again without having to retype them. There are some command line options and switches for DOSKEY to allow you to record macros (long strings of DOS commands that are executed by simply hitting a specified series of keys at the command line), change the way command line editing works and how much buffer size DOSKEY should use for holding the command history.  The best way to get to know these options is to review them in HELP. As it stands, the most common used keys are the up and down arrow keys used to page through the command history, the F7 key which displays the contents of the history buffer thus giving a numbered list of all of the commands available, F8 which searches through the history for a command and F9 which will prompt you for a number from the command list and will execute the stored command corresponding to that number. You can issue the DOSKEY command at any time to begin command recording, but most of the time the command is included in the start-up file AUTOEXEC.BAT so the user has the advantage of command line recall at the beginning of their DOS session.

EXERCISE # 24 – Using DOSKEY

1)	Log on the root directory of drive C: and Issue the command DOSKEY
2)	As you can see, nothing appears to have happened. However, DOSKEY will now start recording anything you type into the command line (including mistakes).
3)	Issue the command CD DOS
4)	Issue the command DIR
5)	Issue the command CD..
6)	Issue the command FIND “dos” c:\dos\readme.txt being sure to use all lowercase for the text string in quotes. Don’t be alarmed that nothing was found.
7)	Now hit the F7 key. You now have a numbered list of all of the commands you entered after starting DOSKEY.
8)	Hit the F9 key and you will be prompted for a command number. Enter the number “1” and hit ENTER. The command CD DOS will appear on the command line. Hit ENTER to execute the command and once again we are logged onto the DOS directory.
9)	Hit the up arrow key repeatedly. One at a time, the commands stored in the history will appear on the command line in order, from the most recent to the very first one issued after DOSKEY started. When you reach the top of the list the up arrow key will stop working. Use the down arrow key to scroll through the commands the other direction until you pass the most recent command and return to an empty DOS prompt.
10)	Using the up arrow, find the FIND command you issued in step 6, but do not hit ENTER.
11)	The reason there were no search results is that “dos” was specified in lower case, and all references to DOS in the README.TXT file are in upper case. Without DOSKEY, if you had issued the command from step 6, discovered your error and wanted to issue the command over using all upper case for “DOS”, you would have had to enter the command all over again. Even after hitting F3 you would have had to backspace all the way to the opening quote mark and start typing the corrected command from there which would have been about as much work as starting the command over. However, with the help of DOSKEY, we can edit the command very easily.
12)	With that FIND command on the command line, use the left arrow key and move the cursor over the “d” in “dos”. Now simply type in DOS over the top of dos and you will replace the lower case letters with upper case letters. Also, because we’re likely to get more than one page of results, hit the “END” key from the group of keys above the arrow keys and this will take the cursor to the end of the command. Add to the end the pipe symbol and the MORE command and hit ENTER.
13)	The corrected command executes and will now also be stored in the history. Hit the F7 key to see the new history list.
14)	Clear the screen with the CLS command.
15)	Now type on the command line the letters FI and nothing else. DO NOT hit ENTER.
16)	Hit the F8 key over and over. This key will locate all commands in the history starting with the letters “FI” and rotate them onto the command line until the specific one you want appears. When it does, you would hit ENTER to execute the command.

Disk Copying

The last section of DOS commands we will look at are the two that effect an entire floppy disk at once. These are DISKCOPY and DISKCOMP. The first, DISKCOPY, is a very often used command. It will create a clone copy of one disk onto another. One very important point is that it can only copy one disk to another if both disks are the identical format. It cannot copy a 720K disk to a 1.44M disk, for example, even though the entire contents of the 720K disk would fit on the 1.44M disk. This is not much of an issue any more because there are so few occasions when you would encounter a 720K floppy disk. However, sometimes books will contain floppy disks in 720K format and even small programs will be distributed on 720K disks. This issue is usually resolved by doing a simple file copy of all contents of the disk onto a new disk. This takes more time and can cause trouble if the source disk contains system or hidden files. Performing a disk copy with DISKCOPY will successfully copy all contents of a disk onto another disk regardless of the types of files it contains.

There are a few things about DISKCOPY that need to be mentioned. First, the source drive and the destination drive can be the same. This tells DOS that it will first read the source disk from a floppy drive and then will prompt the user to remove the source disk and insert the destination disk into the same drive so it can be written to. Another thing is that the entire source disk can be read into a temporary file on the hard disk in one pass so the user doesn’t need to keep exchanging the source and destination disks. This is new for current versions of DOS. In earlier times, DISKCOPY could only read into memory a small part of the disk data requiring the user to swap source and destination disks several times during the copy process. There is a /M switch that will force the newer versions of DISKCOPY to behave like these older versions in case it is undesirable to write to the hard disk during the copy. There is also a /1 switch that will only copy the first side of a disk. It’s use is rather obscure. Finely, like the COPY and XCOPY commands, you can (and always should) use the /V switch which will verify the readability of every sector after it is written.

The DISKCOMP command will conduct a byte-for-byte comparison of 2 disks to be sure they are absolutely identical. This command will determine the number of tracks per side and the number of sectors per track to use for the comparison based on the formatting of the first disk inserted into the drive. Again, you can use a single drive for both disks being compared, and the program will ask you to swap the disks at various times during the compare. This is a VERY time consuming process and shouldn’t be performed on copied disks as a matter of course because it takes forever to do. It can, however, be a powerful diagnostic tool when attempting to hunt down the point where a disk duplicating system is malfunctioning or to see if a “bad” disk is truly different from the master from which it was made. There are only 2 switches for this command. The /8 will only compare the first 8 sectors of each disk regardless of how many sectors there are per track, and the /1 switch will only compare the first side of the disks.

EXERCISE # 25 – Using DISKCOPY and DISKCOMP

1)	Take your bootable floppy and put it in your floppy drive.
2)	Log on to the root of your C: drive and issue the command DEL  C:\TEMP\*.*  to clear out the contents of your TEMP subdirectory.
3)	Execute the command COPY  A:\*.*  C:\TEMP  to copy the contents of your floppy to the TEMP directory.
4)	Replace the boot disk with a completely blank, never before used disk.
5)	Issue the command  COPY  C:\TEMP\*.*  A:  to copy the files from your TEMP directory to the new floppy.
6)	With that new floppy still in the A: drive, reboot your computer.
7)	In theory, you copied all of a bootable floppy to your TEMP directory and then from that TEMP directory to a new floppy. Why didn’t your system boot from the new floppy? This is because the boot files are hidden and thus not copied in operations such as this. You must use the FORMAT command with the /S switch or the SYS command to make a disk bootable. However, perhaps we want to copy a bootable disk that has lots of files on it. Also, what if the bootable floppy is of a different version of DOS then that on your system and the copy disk must contain the same version as the original floppy. In situations like this, you must use DISKCOPY.
8)	Remove the floppy and continue booting from the hard disk. After the system is loaded, put the original bootable floppy in drive A: and issue the command DISKCOPY  A:  A:  /V
9)	When prompted to do so, exchange the original disk for the one you unsuccessfully tried to boot from.
10)	When finished, leave this new disk in the drive and reboot your computer.
11)	This time, the boot should have been successful because even the hidden system files were copied.
12)	Remove this disk and reboot from the hard drive. Put the original disk in the floppy drive and issue the DISKCOMP A: A: command.
13)	This command will take some time to run and you may be exchanging the original and copy disks several times.
14)	When the command ends, note that no differences were found.

CHAPTER 3 QUIZ: Answer T for True and F for False

____ 1)	If you issue a COPY command without a destination argument, the copy will be made 
	to the same directory as the source.
____ 2)	You can rename files as you copy them.
____ 3)	The /V switch causes COPY to do a byte-for-byte check to be sure the copy is exactly 
	like the original file.
____ 4)	You cannot use the REN command to rename directories.
____ 5)	The main difference between COPY and MOVE is that with MOVE, the original file 
	is deleted once the copy has been made.
____ 6)	The RD command will delete a directory and its file contents.
____ 7)	The DELTREE command will remove a directory and any directories under it.
____ 8)	A hidden file cannot be copied with XCOPY.
____ 9)	A read-only file can be erased only if it also has the Archive attribute set.
____ 10)	The PRINT command will print out a copy of the contents of the screen.
____ 11)	Using input redirection and the pipe work exactly the same way.
____ 12)	You can use SORT to create alphabetical lists of items in a text file.
____ 13)	Using the COPY command with CON allows us to send text files to the display.
____ 14)	You can use wild cards to have FIND search all text files for specific contents.
____ 15)	DOSKEY will allow you to reuse a command you have issued by hitting F9 and 
	entering a number.
____ 16)	DISKCOPY will copy any kind disk to any other kind of disk.
____ 17)	DISKCOMP is a way of testing disks you’ve copied.

Chapter 4 – Batch Files

A DOS Convenience

Earlier in our discussions of DOS it was mentioned that DOS recognizes three file types that it will execute as programs. The Executable (.EXE) and the Command (.COM) file types are written in machine code and are executed directly by the microprocessor. The batch file (.BAT) is a bit different. This file is a plain ASCII text file and can be written in any word processor or editor that can save documents as plain text, such as would be seen in a .TXT file. What makes these files special is that they are composed entirely of DOS commands that will be executed in sequence any time the batch file is run.

Batch files automate many DOS setup functions and repetitive tasks. The most common example of this is the batch file DOS creates for itself during install. This file, called AUTOEXEC.BAT, is designed to save the user the mundane task of keying in at the command line all of the system setup commands that allow the computer to function the way it does. During the process of setting up DOS and performing some customizing operations, you edited your AUTOEXEC.BAT file (and also the CONFIG.SYS file that DOS uses at boot-up time to set some of its hardware drivers). At that time we looked at the commands in the AUTOEXEC.BAT file and what they did. Imagine what a pain it would be to have to key in each of those commands at the prompt every time you started your system. This batch file automates this process for you, and we can create other batch files to automate other such processes as you might see fit.

The DOS EDIT Command

In order to create and modify batch files, we’ll be using the EDIT command to launch the built-in DOS text editor. We’ve already looked at this editor a bit, but now we’ll really start using it. Therefore, we should get used to how it works. We’ve already seen how the editor will open a file for us if we list that file name on the command line with the EDIT command. It will also create a new file for us the same way. If we place a file name on the command line as an argument to EDIT and that file doesn’t exist or EDIT can’t find it, it will prepare to create a new file of that name and open a blank document in the editor work space ready for us to create our magic. We can then save our file after we finish creating it or if we choose not to save our work the file will not be created and no damage will have been done. If we start the editor without a file name in the command line, we can simply open an existing file from the FILE menu or just start typing and later save our work by selecting SAVE AS from the FILE menu and giving it a name.

Once in the editor, we can use the mouse to place the cursor where we like in the text or we can use it to highlight sections of text to cut, copy or drag to other locations. In case you don’t have access to a mouse in some situations, these same operations can be performed with only the keyboard. 

EXERCISE # 26 – Introduction to the DOS Editor

1)	Log on to the root directory of drive C:
2)	Open the DOS editor with the EDIT command.
3)	You are greeted with a box telling you that you can either hit ENTER and view a guide on using the editor or hit the ESC key and get right to work. Hit ENTER and review the guide.
4)	This guide is the same screen you get if you hit the F1 key while using the editor. You can view help on different topics by hitting the TAB key to move the cursor to the topic within the green arrows that you are interested in. You can also click on them with the mouse. Each topic will lead to another page with help on that topic or more topic selections to choose from. When you have looked this over a bit, hit the ESC key to clear the help screens and go to the editor screen.
5)	You will see a title bar at the top of the workspace containing the word “Untitled”. This is the current default name of whatever file you’re about to create. Naturally, when it comes time to save your finished file, you will want to rename it.
6)	Hit the ALT key. You will see that the first letter in each of the menu items has turned white and the first item, FILE, has been highlighted in reverse video. Hit the ENTER key and the FILE menu will open.
7)	Hit the ESC key to close the menu.
8)	Hit the ALT key again. Now hit the first letter of another menu items, such as “E” for EDIT and that menu will open.
9)	Hit ESC to close the menu.
10)	Hit ALT again.
11)	Use the left and right arrow keys to move the reverse video highlight from item to item and hit ENTER when the highlight is over the OPTIONS item.
12)	Hit ESC to close the menu. Now you know how to open the menus and select among them with the keyboard.
13)	Using the mouse, click on the SEARCH menu item to open it.
14)	Click anywhere on the workspace away from that menu to close it.
15)	Using any of the above methods, open the FILE menu.
16)	With the mouse, you can click on the OPEN item or with the keyboard hit the “O” key or use the down arrow to highlight OPEN and hit ENTER.
17)	From the resulting dialog box you will see a FILE NAME bar with *.TXT highlighted. This shows that the editor is ready to open any .TXT file it finds. There are none listed in the large FILES box because the root directory contains no .TXT files to choose from. Hit the TAB key once and the cursor will go to the DIRS/DRIVES box. Use the DOWN arrow key to highlight the DOS directory and hit ENTER.
18)	Now there are several .TXT files to select from. Hit the TAB key until the cursor moves to the first file name in the list, likely the COUNTRY.TXT file. Hit the down arrow to highlight the README.TXT file than hit ENTER. This will load the file into the editor (You can also use the mouse to click on these various places to do the same things).
19)	Looking at the editor screen, you will see that there is more text than can be displayed. On the right side of the screen is a scroll bar. Click the mouse on the black square in that bar, hold down on the mouse button and drag the square down. As you can see, you can scroll down and up in the body of the text. Let the mouse button go when you have scrolled down to the part that says “7.4 Converting Other Disk-Compressing Software to DriveSpace”. If you don’t want to use the mouse, repeatedly hitting the PAGE DOWN key will take you there as well.
20)	Using the mouse or the up/down arrow keys, place the cursor somewhere in that line.
21)	Using the mouse or the HOME key, set the cursor to the beginning of that line.
22)	Hit the ENTER key. A new blank line will appear. Remember this technique. You will need to add blank lines in the middle of text often during batch file exercises. Using this technique, always put the cursor at the START of the line BELOW where you want a blank line.
23)	Find another line and using the END key, place the cursor at the end of the text in that line.
24)	Hit the ENTER key and a new blank line will appear after this line. This is the other way of adding a blank line. To use this technique, always but the cursor at the END of the line ABOVE where you want the blank line.
25)	Move the cursor to the center of a line of text.
26)	Hit ENTER. This time instead of adding a blank line we have split the text into two lines at the location of the cursor.
27)	Move to the start of another line in the text.
28)	Hold down the SHIFT key and hit the down arrow key. That entire line will be highlighted.
29)	Hit the DELETE key and the line will vanish.
30)	You have now changed the text. Attempt to exit the editor by opening the FILE menu and selecting the EXIT item.
31)	You will see a box asking if you wish to save your changes. Using the TAB key or the mouse, select CANCEL to abort the exit and return to your document.
32)	If we had selected YES, we would have replaced the current copy of README.TXT with this modified version. Instead, we’ll save it under a new file name.
33)	From the FILE menu select SAVE AS.
34)	In the box you will see the file name listed and the current directory shown as C:\DOS along with a box showing the directories available from the DOS directory. Hit the TAB key and then the down arrow to highlight the “..” entry which is the entry for DOS’s parent directory (the root directory). Hit the ENTER key to select the root directory.
35)	The highlight will return to the file name box where you must enter a name for this file. Enter the name SAMPLE.TXT and hit ENTER.
36)	This will return you to the editor workspace, but now notice that the file name is no longer “Untitled” but “SAMPLE.TXT”
37)	Exit the editor by selecting the EXIT item from the FILE menu.

Manipulating Text

There are ways that allow you to rearrange the text in the editor without having to delete it from one place and type it in again somewhere else. This technique is called cut and paste. What we do is highlight a section of text and “lift” it out of where it is and move it to a new location. This is done by writing the highlighted test into a place in memory called the “clipboard”. The clipboard will store this text for as long as the EDIT program is running, so it’s possible to take text from one document, open another document and insert the text there.

There are three operations selectable from the EDIT menu associated with the clipboard. The first two move text into the clipboard. One is CUT and the other is COPY. The first will remove the text from its original location and the second will only copy the text to the clipboard but otherwise not disturb it. The third operation, called PASTE, takes the text in the clipboard and inserts it into the document at a new location. Once text is in the clipboard, it can be pasted over and over into as many locations as you wish. If, however, you cut or copy new text into the clipboard, whatever text that may already be there is erased and replaced by the new text.

EXERCISE # 27 – Cut and Paste

1)	Log on to the root directory of drive C:
2)	Re-enter the editor but this time add the file name on the command line. Issue the command EDIT  SAMPLE.TXT
3)	This time the editor screen is displayed immediately and with the text of the document loaded and ready to edit.
4)	Hit the PAGE DOWN key 5 times until you reach the part that says “1.  Setup”.
5)	Using the up and down arrow keys, place the cursor on that line and the HOME key to make sure it is at the start of the line.
6)	Hold down on the SHIFT key and hit the down arrow 11 times so you highlight from “1.  Setup” through “…/E at the command prompt.”
7)	Hold down the ALT key and hit the “E” key to open the EDIT menu. Release the ALT key. Hit the “T” key to select the CUT option.
8)	The highlighted text will vanish. This text is now stored in the clipboard.
9)	Use the PAGE DOWN key to move to the area that says “2.5 MemMaker and Adaptec SCSI Devices”
10)	Place the cursor over that line and use the HOME key to place the cursor at the start of the line.
11)	Hold down ALT and hit “E”. Release the ALT key. From the EDIT menu hit the “P” key.
12)	The text you cut from one part of the document and stored in the clipboard has been spliced or “pasted” into the document at this new location.
13)	We can insert this text again someplace else because it is still stored in the clipboard. Move the cursor a few pages down and repeat step 10. Do this several times in different places in the document.
14)	Highlight another section of text and this time select COPY from the EDIT menu. The highlighted text is undisturbed.
15)	Move to another place in the document and select PASTE from the EDIT menu. Note that what is pasted is your newly copied text and the original text from step 6 is gone.
16)	Try this again but this time use the mouse. Place the mouse at the start of a line, hold down the mouse button and drag the mouse over a few lines. As you do so, that text becomes highlighted. After highlighting a few lines, release the mouse button. The text remains highlighted.
17)	Use the mouse to select the EDIT menu and then the CUT item. The text vanishes into the clipboard.
18)	Move the cursor to another location and with the mouse, select the EDIT menu and then PASTE. The text is inserted.
19)	Exit the editor without saving your changes.

BATCH file Commands

There are some DOS commands designed specifically for batch file processing. We have already seen one, the ECHO command. In a batch file, this command displays test to the screen and can be used to offer information, status reports or prompts to the user. The ECHO command has another use. By issuing the command ECHO OFF, we can tell DOS commands that generally display status information to the screen to not do so. In fact, a batch file will display each line it is executing as it executes it unless that display is suppressed with the ECHO OFF command. To take things a step further, the very command ECHO OFF itself will be echoed to the display unless it is suppressed with another command which is the @ sign. The @ sign will suppress display only of the command that comes after it on the line. Therefore, to suppress the display of the commands in a batch file as well as that command to suppress display, we would use @ECHO OFF as the first line in the batch file. We can also use the command ECHO. (there is no space between the ECHO and the period) to generate a blank line like we did when we used ECHO to write headers to our sort files in the last chapter. This can help brake up the text and make it more readable.

The PAUSE command will halt the execution of the batch file, display the prompt “Press Any Key To Continue…” and wait for the user to press a key before continuing with the next command. This allows the user to read important output from the batch process, receive instructions on using the batch file or otherwise catch their breath before allowing the process to resume.

IMPORTANT NOTE: In the following exercises and other text examples, I have presented batch file text in all caps with the commands in bold. You DO NOT need to use upper case in your text. I use it here to help make the text more readable. The only place where DOS is case sensitive is with the spelling of variable names as will be pointed out later. Also, there is no problem with having extra blank lines between lines of code. It is good programming form to avoid this in batch files but makes no difference to DOS when it comes time to run them. However, use only one space character between parts of a command and other elements on a line that require space. Also make sure to leave that space between separate elements and arguments. This rule is the same as for using DOS commands at the prompt.

EXERCISE # 28 – Writing  a simple BATCH file

1)	Be sure you’re in the root directory of drive C:.
2)	Start the editor with EDIT  TEST.BAT
3)	The editor will start and offer a blank workspace titled TEST.BAT
4)	Type in the following four lines of text:
echo This is a test batch file.
echo.
pause
echo This ends the test
5)	from the FILE menu select EXIT. You will be asked if you want to save your work. Select YES.
6)	At the prompt, issue the command TEST to run your batch file
7)	You will see your opening line and a prompt to hit a key to continue. Hit a key and the batch file will continue to its end.
8)	Notice how the lines in the batch file were echoed to the screen as command prompts with commands. We need to clean this up. Also note that it can be hard to see where the batch file starts because the screen has other stuff on it left over from previous operations. Let’s modify the batch file to offer better appearance. We can use ECHO OFF to suppress the command lines.
9)	Again issue EDIT TEST.BAT
10)	With the cursor at the first line, hit ENTER to add a blank line above it.
11)	In this new line type   echo off   but don’t hit ENTER because we don’t need any more blank lines (although it wouldn’t matter if you did).
12)	Exit and save. Run the file again.
13)	Notice how easy it was this time to read and understand the output of the batch file. However, we still got the echoing of the ECHO OFF line.
14)	Issue EDIT TEST.BAT
15)	With the cursor at the start of the first line, type an @ sign so it is inserted in front of ECHO OFF
16)	Exit and save, then run the file again.
17)	Now we’re cooking! However, let’s take it one more step.
18)	Issue EDIT TEST.BAT and with the cursor at the start of the first line hit the END key to go to the end of that line.
19)	Hit the ENTER key to generate a blank line for a new second line.
20)	In that blank line type   cls   so that the batch file clears the screen.
21)	Exit and save. Run the file and notice how much easier it is to understand the output when the batch file cleans up the clutter on the screen before it starts.

Congratulations! You have written and run what may have been your very first program! Now we need to learn how to put batch files to work. Because it is so convenient to use batch files to automate redundant or often reused sequences of DOS commands, let’s look at how to do that. As a general rule, anything you can do at the command line you can do in a batch file as well as many things that simply have no use at the command line such as the PAUSE command we saw in the last exercise. There are other commands that COULD be used at the command line, and sometimes are for testing purposes, but show their true power in batch files.

Result Codes and ERRORLEVEL

Almost all DOS commands generate a result code. This is a number, usually either a zero to indicate that the command executed successfully or a non-zero number to indicate any one of several possible errors took place. These result codes are available to your batch files by using the command ERRORLEVEL. With it you can test the result of many DOS commands and have your batch file respond accordingly. One of the most common places where ERRORLEVEL is used is with the CHOICE command. You can generate a menu in your batch file and offer the user choices as to what they want the batch file to do. The response the user gives back can be determined by evaluating the ERRORLEVEL return code from the CHOICE command. The way it works is simple. You use the ECHO command to list a series of options to the user and indicate that the user may choose one of them by hitting a specific key. The CHOICE command is set up to expect those specific keys and the order in which you list them in the CHOICE argument list determines what ERRORLEVEL number will be assigned to each key. Once the user hits a key, CHOICE returns the key number and your batch file branches accordingly.

Setting up CHOICE has a lot of options. If there are no arguments offered with the CHOICE command, its default action is to accept Y for YES and N for NO. Y will be assigned an ERRORLEVEL of 1 and N an ERRORLEVEL of 2. If you use the /C switch, you can specify which keys are allowed and in what order they will be assigned ERRORLEVEL numbers. CHOICE will also display a list of the allowed keys unless you use the /N switch, which will suppress the display of the valid keys. The /S switch forces CHOICE to make the valid keys case sensitive. Without it, either upper or lower case keys will result in the same selection. The last switch is /T and allows you to specify a default key selection and an amount of time in seconds that the user has to make a selection before CHOICE uses that default key and answers for them. After the switches, you can supply some text in quotes that CHOICE will display as a prompt to the user. If you set up a menu, you may not want to use this prompt option. However, if you’re offering a simple YES/NO question, using the prompt option allows the CHOICE command to do all of the work itself.

Making Decisions in a BATCH File

Now that you have an ERRORLEVEL return code, either the result of a command or a user selection, how do we test for its value? The answer is with the IF command. The IF command allows us to take action based on whether the results of a test are true or false. This action is referred to as “branching” in the code. We come to a fork in the road and go either left or right depending on the results of a decision. The form for using IF is:

IF (SOME CONDITION) COMMAND

In terms of using it with the CHOICE command, let’s take the following example. We will use the CHOICE command to offer the user a simple YES/NO question with a timer of 30 seconds after which time the YES will be selected automatically. CHOICE will also generate the prompt for the user.

@ECHO OFF
CLS
CHOICE /T:Y,30 “Start Windows Now?”
IF ERRORLEVEL = = 2 GOTO STOP
IF ERRORLEVEL = = 1 WIN
:STOP
ECHO You Are In DOS

Let’s look at the above sample batch file. First we see the @ECHO OFF line and the CLS line which were explained in the last exercise. Next we have the CHOICE command. There is no /C argument listing the allowable keys, so CHOICE defaults to Y and N. There was no /N argument, so when the batch file is run, CHOICE will list the two valid keys in the screen so the user knows they can select Y or N and that’s all. This list of allowable keys is displayed for the user immediately following the prompt. After 30 seconds are up and the user hasn’t attempted to make a selection, the “Y” will be chosen for them. Be aware that if the user hits a key, ANY KEY AT ALL not on the list of valid choices, CHOICE will stop timing and will sit there forever waiting for the user to select a valid key as if the /T argument had never been used.

If the user makes a selection before the timer runs out or if CHOICE makes the selection itself after 30 seconds, the command ends and the first IF statement is evaluated. Notice the use of the double “= =” equal signs in the IF statement. Using two equal signs sets up a comparison to test if the variable on the left, in this case ERRORLEVER, is equal to the value on the right, in this case, the number 2.  If the user selected "N", then CHOICE would assign ERRORLEVEL a value of 2 and the first IF statement would evaluate as true. It would then execute the command on the line with it, in this case the GOTO command. This is another branching command. It will cause all commands to be skipped until it reaches a line with only a colon and the argument of GOTO on it. In this case, execution will move to the command on the line after the one with the label “STOP” and run the ECHO statement. On the other hand, if the user had selected Y, then CHOICE would have set ERRORLEVEL equal to 1 and the first IF statement would fail. However, the second IF statement would evaluate as true and the command WIN would execute. This command is actually the file named WIN.COM and starts Windows 3.1, but as you remember, DOS makes no distinction between one of its own commands and the name of an .EXE, .COM or .BAT file. It will therefore start Windows. Once Windows is shut down, DOS will go back to finishing this batch file. It will therefore finish by executing the ECHO on the line after the :STOP label. These sorts of arrays of  "IF ERRORLEVEL…" statements one after the other is often called a "decision tree" or simply "tree".

One important thing to remember about testing ERRORLEVEL numbers is to always test them starting with the highest number and going progressively lower. We’ll see how this works when we get to the exercises.

Another use of the IF command is to test the outcome of another command. For example, you could have a line like:

IF EXIST C:\WORK\*.DOC  COPY C:\WORK\*.DOC C:\TEMP

This line sets up a condition that uses the EXIST command to see if there exists any files matching the pattern C:\WORK\*.DOC. If there are any .DOC files in that directory, then the result of the test is true and the command COPY C:\WORK\*.DOC C:\TEMP is executed thus backing up all of the .DOC files in that directory to the TEMP directory (you can also put the word NOT in front of EXIST to test for opposite condition). In a batch file, error messages generated by commands are displayed to the screen just like they are on the command line. Thus, if there were no .DOC files in that WORK directory, simply issuing the COPY command would have resulted in the display of the error message stating that no files could be found. This is considered bad form in programming. The IF test is used to prevent the command from even being issued in the event there are no files for it to operate on.

EXERCISE # 29 – Making Decisions in DOS

1)	Because we will be editing and running the next batch file several times, first load DOSKEY so you can use the up arrow to quickly select either the editing command or the running command without having to type it in each time.
2)	Log on to the root directory of drive C: and issue the command EDIT  SELECT.BAT to create a new file for us to work on.
3)	The first 2 lines should be second nature to you by now:
@ECHO OFF
CLS
4)	Next we will create a menu for the user to select from:
ECHO Select From the Following Start-up Options:
ECHO Hit S to run SCANDISK
ECHO Hit A to run Anti Virus
ECHO Hit B to run Backup
ECHO Hit X to go directly to the DOS prompt (default in 15 seconds)
5)	Now we enter the CHOICE command and the ERRORLEVEL tests.
CHOICE  /C:SABX  /T:X,15  “Make Your Selection Now >”
IF ERRORLEVEL = = 1 GOTO SCANDISK
IF ERRORLEVEL = = 2 GOTO MSAV
IF ERRORLEVEL = = 3 GOTO MSBACKUP
IF ERRORLEVEL = = 4 GOTO DOS
6)	Next, we add our GOTO labels and the commands to be executed once we get to them:
:SCANDISK
ECHO SCANDISK
GOTO END
:MSAV
ECHO MSAV
GOTO END
:MSBACKUP
ECHO MSBACKUP
GOTO END
:DOS
ECHO DOS
:END
ECHO FINISHED!
7)	Exit EDIT and save your new file. Run the file by issuing the command SELECT
8)	We haven’t added any commands to the choices yet other than to simply ECHO the name of the command we would like to run because we want to make sure each key does what we expect. First, just let the 15 seconds go by and see if we get the DOS message.
9)	That didn’t seem to work. Use the up arrow key and let DOSKEY place the SELECT command back on the command line and run it again. This time, hit the “A” key and see what happens.
10)	Oops! It listed SCANDISK again. 
11)	Try again and hit the “B” key
12)	As you can see, all of the selections result in the listing of only SCANDISK.
13)	Use the up arrow key and find the EDIT  SELECT.BAT command and reopen the editor.
14)	If you remember, there was mention that the ERRORLEVEL values must be tested starting with the highest number and working down. We have done the opposite and started with the lowest and gone up. Change each line in the ERRORLEVEL test group to read like this:
IF ERRORLEVEL = = 4 GOTO DOS
IF ERRORLEVEL = = 3 GOTO MSBACKUP
IF ERRORLEVEL = = 2 GOTO MSAV
IF ERRORLEVEL = = 1 GOTO SCANDISK
15)	Exit with save and run the batch file again.
16)	Now as you make your selections, the correct text is displayed. We’re now ready to remove the ECHO part from each command and make the batch file really start these programs for us.
17)	Reopen the editor and move the cursor to the line that reads ECHO SCANDISK
18)	 Use the DELETE key to remove the word ECHO. Do the same for the ECHO MSAV, ECHO MSBACKUP and remove the entire line that says ECHO DOS
19)	As you might be able to conclude, there is no real use for the :DOS label any more and we can go back up to the ERRORLEVEL statement that says GOTO DOS and change that to GOTO END
20)	Now remove the :DOS label from the batch file.
21)	Save the file and run it. Try each selection and see how the batch file can be used as a utility menu to launch programs that keep your system tuned up.
22)	Let’s make a few more refinements. Reopen the file in the editor.
23)	Add a blank line between the @ECHO OFF line and the CLS line. In that line add the label line :START
24)	Change all of the GOTO END lines under the :SCANDISK, :MSAV and :MSBACKUP labels to read GOTO START instead.
25)	Add a new line between the “ECHO Hit X to go…” line and the CHOICE line. In that new line add ECHO. and don’t forget the period. This will add a blank line between the menu and the CHOICE prompt and clean up the appearance of the text.
26)	Add a line between the “ECHO Select From…” and the “ECHO Hit S to…” lines and place an ECHO. line there as well.
27)	There is no real reason to have CHOICE list the valid keys, so before the prompt text in CHOICE, add the argument /N.
28)	Save and exit. Run the batch file and notice that after each command has run you are returned to the menu so you can run another one if you wish. Selecting the “X” option is the only way to exit the program. Try it.
29)	You can also abort the batch file by holding the CTRL key and hitting the “C” key which, if you remember, is the way to abort any DOS command that may be running. Run the batch file and at the menu use the CTRL C method of exiting. In this case you will be asked if you wish to cancel the batch job. Hit the Y key and you will be back at the prompt.

A point to keep in mind about using ERRORLEVEL in "selection trees" like this is that you must branch execution of the batch file away from the tree once a valid selection has been found. In the above exercise, we did this by using a GOTO branching command as the command to be run if the IF test turned out to be true. It might occur to you that it would be easier just to place the command to be run on the line with the ERRORLEVEL test like:

IF ERRORLEVEL = = 2 MSAV

However, once MSAV has run, the contents of ERRORLEVEL become undefined. The command MSAV will set the ERRORLEVEL value when it completes, and that value could be anything depending on how the virus scan came out. Therefore, it could have unpredictable results once that line finished and execution continued with the next "IF ERRORLEVEL…" line. For this reason, except for the very last ERRORLEVEL test, you must branch execution away from the rest of the tree. This isn't needed all of the time with the last ERRORLEVEL test because, being the last line in the tree, there are no more tests to be performed and the value of ERRORLEVEL cannot have any further effect on the selection process. Consider the following example:
CHOICE /T:N,15 "Delete all TMP files before running Word Perfect"
IF ERRORLEVEL = = 2  GOTO RUNWP
IF ERRORLEVEL = = 1  IF  EXIST  C:\WP\TEMP\*.TEMP  DEL  C:\WP\TEMP\*.TMP
:RUNWP
WP

Here we have two choices, yes or no. If we answer no, then we use GOTO RUNWP to exit the tree and run Word Perfect by issuing the command WP which is the Word Perfect program file name. If we had answered yes, then the commands EXIST to check for temp files and then DEL to remove them will be run. However, because there is nothing to be done after the deletions and before the running of WP, we didn't need to use a GOTO to branch away from the tree. In this particular case, we really didn't even need that "IF ERRORLEVEL = = 1…" line at all because if the "IF ERRORLEVEL = = 2…" line hadn't triggered, then the only other possibility was the other answer, so there is no real point in testing for it. We could have written the code like this:

CHOICE /T:N,15 "Delete all TMP files before running Word Perfect"
IF ERRORLEVEL = = 2 GOTO RUNWP
IF EXIST C:\WP\TEMP\*.TMP  DEL C:\WP\TEMP\*.TMP
:RUNWP
WP 

As you can see, you need not always test for the last possibility because you have already exhausted all of the other choices by then anyhow. 

An exception to the rule of always branching away from the selection tree is the case of having the IF line simply ECHO something to the screen if the result is true. An ECHO will not change the ERRORLEVEL value and so not cause other ERRORLEVEL tests to turn out true.

Adding Remarks to a BATCH File

You may need to place notes to yourself in batch files so when you go back to change or update them, you have remarks in specific places to remind you what’s going on there. The remarks are easy to place. You just issue the REM command and anything on the line with it is ignored by DOS. This makes it easy to embed notes to yourself or other programmers into your batch files.

EXERCISE 30 - Adding Remarks to a BATCH File

1)	Open the last batch file with EDIT SELECT.BAT
2)	Create a new line below @ECHO OFF
3)	In that line add REM System Start-up Utilities Menu SELECT.BAT Created (today's date) by (your name).
4)	Hit the ENTER key to create another new line and on that line place a single REM command. This will add some space between the title and the text.
5)	Create a blank line just above the "ECHO Select from the following…" line.
6)	In that new line add REM  *** This is the Selection Menu.
7)	The use of the stars is to help set your comments apart from the rest of the batch file to help make them easy to find and read. Make sure there is ALWAYS a space between the REM command and any text (stars or otherwise) that follows it .
8)	Add a new line just above the CHOICE command.
9)	In that line add REM  *** Select an Option
10)	Now add a line just under CHOICE.
11)	Add the line REM  *** Selection Tree
12)	Add a line between the last ERRORLEVEL line and the :SCANDISK line.
13)	In that line add REM  *** Vector List
14)	At the end of the file make a new last line and type REM  *** End Of File
15)	Look the file over. It should now be easy to make out the different sections of the file as well as the purpose of the batch file and the end of the file text.
16)	Save and close EDIT.

The FOR Loop

Batch files make good file management tools. You can create batch files to automate common routines like cleaning up TEMP directories, backing up work files and the like. Sometimes it may be necessary to carry out the same operation over and over. A command that allows you to carry out the same set of commands for so long as some condition exists is the FOR command. This is often called a “looping” command because it causes your file to loop over and over until some pre determined condition is satisfied. We created a simple loop condition in the last batch file using GOTO statements and labels. This allowed us to loop back through the menu and CHOICE commands until the user decided to exit the batch file. The FOR loop command will do the same thing, just do it for specific situations. The FOR command is used with the keywords IN and DO to form a complete a sentence of sorts.

The syntax of the FOR command looks like this:
FOR (some variable or condition) IN (some set of data) DO some command (perhaps with the variable as an argument)

In plain English, the command says that for so long as some condition exists within some target, a specific command it to be repeated over and over until the condition is no longer met. To take the place of the variable, we use the DOS symbol for an unknown quantity which is a label or name preceded by a percent sign. However, in a FOR loop, these variables must have double percent signs such as %%A. The label can be anything, but it is convenient to use a single letter for the label. Don’t use numbers because these kinds of variables mean something special to DOS, unless you specifically intent to use the number variables that DOS has pre-defined. Also keep in mind that variables are case sensitive, so %%A will be a different variable then %%a. When the batch file is run, DOS will automatically insert into that variable, for example, the name of one of the files in some location and carry our some operation on this file and then next time through the loop use the next file in line until it has gone through all of the files. Let's try an example and then we'll use an exercise to really make it happen.

FOR %%A IN (*.TMP *BAK *OLD) DO DEL %%A

This FOR command says "For so long as I can fill %%A with the name of a .TMP file, a .BAK file or an .OLD file in this default directory, I will delete that file. Once I have gone through all of the files, I will stop." 

This particular example isn't very impressive, but should help explain how the command works. Using the FOR loop in this way isn't the only way to perform the above deletions. However, from a programming point of view, it's much more efficient that using 3 lines like this:

IF EXIST *.TMP DEL *.TMP
IF EXIST *.BAK DEL *.BAK
IF EXIST *.OLD DEL *.OLD

The programming imperative states that if you can do something in one line of code that would ordinarily take three lines of code, use the one-liner. Also note that in a FOR loop we don't need to do the IF EXIST test because the FOR loop simply won't execute for files that are not there and will for files that are there.

We can also set up a FOR loop to do something a set number of times by using a number count as the data set. Look at this loop:

FOR  %%A  IN  (1 2 3 4 5)  DO  COPY  PAYROLL.DOC  PAYROLL%%A.BAK

This loop will place in the variable %%A a number from the data set (1 2 3 4 5) and so long as there are numbers, it will copy PAYROLL.DOC with a new name. The first time through the loop, %%A will be set to the first data in the data set which will be the number 1. Because the copy command adds the contents of the %%A variable to the file name when it is copied, a file named PAYROLL1.BAK will be created the first time through the loop. The second time through the loop, %%A will be set to 2 and create the file PAYROLL2.BAK. This continues until the file PAYROLL5.BAK is created at which time the FOR loop has used all of the members of the data set and will stop. Using this loop, you have created 5 backup copies of the file PAYROLL.DOC. You can also run this kind of FOR loop from the command line (the DOS prompt), but at the command line you use single % percent signs for variables instead of double %%.

EXERCISE # 31 - Looping

1)	Log on to the root directory of drive C:
2)	If you have restarted your system sense the last exercise, reload DOSKEY.
3)	Start a new file with EDIT  CLEANUP.BAT
4)	On the first line type @ECHO OFF
5)	On the next line type REM Temp File Clean-up program CLEANUP.BAT Created (today's date) by (your name).
6)	On the next line type REM
7)	On the next line type CLS
8)	On the next line type REM  *** Changing to the root directory.
9)	On the next line, type CD\
10)	On the next line type REM  *** The FOR Loops.
11)	On the next line type REM  *** The first one deletes all *.TMP, *.BAK and *.OLD files from the root directory.
12)	On the next line type ECHO Deleting all .TMP, .BAK and .OLD files…
13)	On the next line type FOR  %%A  IN (*.TMP *.BAK *.OLD) DO  DEL  %%A
14)	On the next line type REM  *** This one backs up all batch files and CONFIG.SYS to the TEMP directory.
15)	On the next line type FOR  %%A  IN (*.BAT *.SYS) DO  COPY  %%A  C:\TEMP
16)	On the last line type REM  *** End of FILE
17)	Save and exit
18)	Now we need to create some victim files for this batch file to fine and delete. At the command line type COPY *.BAT *.TMP and hit ENTER. This will copy all batch files as .TMP files. 
19)	Next type COPY *.BAT *.BAK and hit ENTER. This will create a bunch of .BAK files.
20)	We will not make any .OLD files just to see that not having any generates no error message in the FOR loop.
21)	Issue the DR command and hit the F7 key to sort the contents alphabetically. Notice that each .BAT file now has a companion .BAK and .TMP file. Exit DR.
22)	Now run CLEANUP
23)	As you can see, there was no complaint of not being able to find any .OLD files to delete, and there was also conformation of several files having been copied.
24)	Run DR again and notice that all .BAK and .TMP files are gone and only the .BAT files remain.

This might be a handy program. Let's add it to the list of options in SELECT.BAT.

EXERCISE # 32 - Running One BATCH File From Another

1)	Open the menu batch file with EDIT SELECT.BAT
2)	Add a line just under "ECHO  Hit B to run Backup"
3)	On that line add ECHO Hit C to Run Clean-up
4)	Now in the list of allowable keys in the /C argument of CHOICE, place the letter C between B and X.
5)	Add a new line under "IF ERRORLEVEL = = 4 GOTO END"
6)	In the line above, change the 4 to a 5
7)	On that new line type IF ERRORLEVEL = = 4 GOTO CLEANUP
8)	Add a new line above :END
9)	On that line type :CLEANUP and hit ENTER to create another new line.
10)	On that line type CLEANUP and hit ENTER to add another new line.
11)	On that line type GOTO START
12)	Save and exit. Run SELECT
13)	From the option menu, select "C" and run CLEANUP.BAT
14)	That's odd! You’re now at the DOS prompt when you should have looped back to the start and redisplayed the selections menu. What happened?
15)	Reopen SELECT.BAT in the editor.
16)	The line that issues the command to run CLEANUP.BAT says CLEANUP and is the one just under the line containing the label :CLEANUP. Change the line that issues CLEANUP.BAT to read CALL CLEANUP instead of just CLEANUP
17)	Save and Exit, then run SELECT again.
18)	Hit the "C" key from the menu.
19)	This time when CLEANUP.BAT finishes, you are taken back to the menu as you would expect.
20)	You may have noticed that the CLEANUP program was run, exited and then the SELECT program cleared the screen to redraw the menu before we could read the messages that CLEANUP gave us.
21)	We need to allow the user to read those messages by adding a PAUSE to CLEANUP. 
22)	Reopen CLEANUP.BAT in EDIT
23)	Make a new line just above the very last one.
24)	In that new line type PAUSE
25)	Save and exit. 
26)	Now run SELECT again and hit the C option.
27)	This time, CLEANUP paused to allow us to read the messages. After hitting a key in response to the PAUSE prompt, CLEANUP exited and SELECT was allowed to clear the screen and redraw its menu.

The CALL Command

What we see in the above exercise are the two ways to run a batch file from within another batch file. The first way is to simply place the file name like a command on a line in the batch file. When you do this, you execute a "jump" to that second batch file. As far as DOS is concerned, that second batch file is the only batch file running. Once that batch file has run, execution ends. There is no way back to the original batch file that ran the second one. This is unlike regular DOS commands, .EXE files and .COM files. In any of these cases, once the command or program ends, DOS returns to the batch file and continues running. This is referred to as a "call" instead of a "jump". We can make batch files do this by using the CALL command to run the second batch file. This way, DOS keeps its place in the original batch file and when the called batch job ends, DOS go back to the original batch file and picks up where it left off just like it does with any other command. Something to keep in mind about this. If you WANT to jump to the second batch file, then you can put that jump on the same line as the ERRORLEVEL test like this:

IF ERRORLEVEL = = 4 CLEANUP

Because you will never be going back to that batch file with the ERRORLEVEL statement in it, there is no risk of other ERRORLEVEL statements becoming confused. However, as with the above example, we wanted to return to the calling batch file after running CLEANUP so we branched away from the tree like we should and used the CALL command.

Command Line Arguments for BATCH Files

As with most commands and many .EXE and .COM programs, you can add arguments to the command lines of batch files and have the batch file read the argument and operate on it. For example, suppose your CLEANUP.BAT file could accept an argument that allowed you to select which directory to save the .BAT and .SYS files in. What if you wanted to save them to floppy instead of the hard disk some of the time? Wouldn't it be nice to issue the command like:
CLEANUP C:\STASH
or
CLEANUP A:

Well, you can do that. Remember when we discussed the names of the FOR loop variables and it was mentioned not to use numbers because numbered variables already have a function in DOS batch files? Well, that function is to pass along command line arguments to the inner workings of the batch file. Command line arguments become variables in the batch file automatically. In this case, the variable is a number preceded with a single percent sign. The first variable, which would be %0, is the name of the command itself and is seldom used. However, the first argument on the command line after the command is assigned the name %1, the second argument %2 and so on up to 9 arguments. Actually, there is a way to get more than 9 arguments on the command line by using the SHIFT command but we'll not go into that command here.

Remember, unlike the FOR loop, these variables and most all other variables in DOS use a single % percent sign. Don't get confused on this issue or you will spend a lot of time debugging your batch files!

Let's use this technique on the CLEANUP.BAT file we already have. We need to be able to use it two ways. If we supply a directory as an argument, then we will use it. If no argument is issue with the command, then we will continue to use the TEMP directory we already coded for. The changes are very simple. Let's rebuild CLEANUP.BAT.

EXERCISE # 33 - Using Command Line Arguments

1)	Issue the command EDIT CLEANUP.BAT
2)	Add a new line after the first FOR loop line.
3)	Type REM  *** Check for a command line argument and hit ENTER.
4)	On the next blank line type IF "%1" = = "" GOTO NODIR and hit ENTER (don't forget the quote marks around "%1".
5)	On the next blank line type REM  *** Use the argument as a backup location and hit ENTER.
6)	On the next line type FOR  %%A  IN (*.BAT *.SYS) DO COPY  %%A  %1  and hit ENTER.
7)	On the next line type GOTO END and hit ENTER.
8)	On the next line type :NODIR
9)	Add a new line above PAUSE
10)	In that line type :END
11)	Save and exit.
12)	Put a floppy in drive A: and run CLEANUP A:
13)	Issue the command DIR  A:
14)	As you can see, the backups were written to the floppy.

The reason we rewrote this file to either accept an argument or not is so we didn't have to change SELECT.BAT that also uses this file and expects to save to the TEMP directory without having to give any command line arguments. Thus, we have made sure the file is backwardly compatible with any previous uses. We took nothing away from its functionality, but added something new. This is an important consideration when changing the way any program works. You must ask yourself how changing the program will impact on current uses of the file.

There are a few things that need to be pointed out. First, there is the use of the double equal signs to test the contents of variable %1. As when we used them with ERRORLEVEL, they're used here to set up a comparison between the contents of the variable and a "null string" or an empty value signified by the double set of quote marks with nothing between them. Basically we're asking "Is this variable currently equal to nothing?" and if it is, we go to the label :NODIR and run the FOR loop we had originally programmed. If, on the other hand, the result of the test is false and %1 does contain something, we move on to the new FOR loop and use that %1 variable in place of the C:\TEMP directory from the original loop. Thus, we have carried the users request from the command line to the working FOR loop. After the FOR loop ends, we now must jump around the original loop to the :END label otherwise we would end up running that original loop as well.

CHAPTER 4 QUIZ: Answer T for True and F for False

____ 1)	A batch file can be written on a word processor as a .DOC file.
____ 2)	With the DOS editor, you can remove sections of text and place them in another 
	document.
____ 3)	To create a new line in a document, place the cursor in the middle of a line and hit 
	ENTER.
____ 4)	The ECHO command will allow you to run a DOS command twice.
____ 5)	To help make the output of a batch file easier to read, it is good to start the file with 
	the line ECHO with a period after it.
____ 6)	Most DOS commands return a result code that can be accessed by testing the 
	ERRORLEVEL value.
____ 7)	If you use the CHOICE command with no arguments, you cannot use any keys to 
	answer the prompt.
____ 8)	The only time you use a single % for a variable is at the DOS prompt. All variables in
	batch files use double %% no matter where they appear.
____ 9)	When evaluating ERRORLEVEL you need to build a tree of IF statements that test
	the value of ERRORLEVEL starting with the highest value and working down.
____ 10)	You use double equal signs in a batch file to represent the operation of comparison 
	between two variables or a variable and a known value.
____ 11)	The GOTO command will jump to a label only if that label is on a line below the line 
	where the GOTO statement is located.
____ 12)	No matter how many choices are offered by the CHOICE command, there must be an 
	ERRORLEVEL test for each of them.
____ 13)	You can use the CTRL “C” key combination to abort from a batch file.
____ 14)	A REM command will display on the screen comments left by the programmer when 
	the batch file is run.
____ 15)	When the FOR loop is able to run the command after DO one time successfully, it 
	exits.
____ 16)	The only purpose for using the CALL command to run a batch file from another batch 
	file is to prevent confusing the ERRORLEVEL tree.
____ 17)	When using command line arguments within a batch file, the first argument is 
	assigned to the variable called %1.

Index of DOS Commands

%			56,59
%%			55
/			10,15
/?			16
:			50,51
= =			50
@			48
ATTRIB			34
CALL			57,58
CD			9,11,14
CHKDISK		9
CHOICE			49
CLS			9,12,16,41
CON			38
COPY			9,30
DEFRAG			20,22
DEL			31
DELTREE		32
DIR			9,11,15
DISKCOMP		41,42
DISKCOPY		10,41,42
DOSKEY			40
ECHO			38,39,47
ECHO OFF		48
EDIT			13,16,31,44
ERASE			31
ERRORLEVEL	49
EXIST			51,54
FC			30
FDISK			19,21
FIND			39
FOR			55
FORMAT			9,12,16,19,21,42
GOTO			50,51
HELP			16
IF			50
LABEL			19
MD			23,33
MEMMAKER	39
MORE			27,33,36
MOVE			31,32
MSAV			9,21,52
MSBACKUP		21,22,27,52
NOT			51
PATH			9
PAUSE			48,58
PRINT			35
PRINT SCREEN	35
PRN			35
RD			31,33
Redirection < > >>	35,36,37,39
REM			54
REN			31
RENAME		31
SCANDISK		13,16,20,51
SHIFT			59
SORT			37,39
SYS			7,10,13
TREE			27
TYPE			12,16,36
UNDELETE		21
UNFORMAT		19,20,21
VER			11,14
VOL			19
XCOPY			16,30,33,34,42