Robert W. Weeks bob.weeks@cox.net, http://members.cox.net/bob.weeks
Course Objective
Participants completing this course in Hard Disk Management will be able to manage their hard disks effectively. Specific skills include the ability to copy files, to create and maintain a directory structure, to perform effective and efficient backups, and to save time and effort by using batch files.
Prerequisites
The prerequisite for this class is a basic understanding of the DOS (Disk Operating System) used on IBM and compatible computers. Our class, however, starts with a review of the basic commands. It is helpful if you've worked with software that creates files, such as a spreadsheet, database, or word processing program, so that you can understand how the procedures you'll learn relate to your specific situation.
Storage Measurement
Bit
A bit or binary digit is either a zero or one. Computers internally work in the binary or base two numbering system, where the only digits available are zero and one. (Electrically, a zero is expressed as a low voltage, and one by a higher voltage.) All data in the computer--a spreadsheet, paragraph of text, database, graphic image, whatever--is expressed as a sequence of zeros and ones.
Byte
A byte is eight bits. It's roughly equivalent to one character in word processing and database applications. In spreadsheet applications, numbers are usually stored in four or eight bytes, regardless of the size of the number. The byte is a more useful unit of storage than the bit, because a byte is generally equal to one character. This is just an approximation, but is true in general use.
Kilobyte
The kilobyte, which is abbreviated K or KB, is exactly 1,024 bytes (210 = 1,024). Although the kilobyte is precisely 1,024 bytes, in common use a kilobyte is about 1,000 characters. A typewritten page of information generally uses two to four kilobytes of storage. Many PC's today have 640 kilobytes or more of RAM as a standard feature, and floppy diskette capacities range from 360 to 1,440 kilobytes.
Megabyte
The megabyte, abbreviated MB, is 1,024 kilobytes or 1,048,576 bytes. In common usage, however, we say a megabyte is about 1,000,000 characters. Typical capacities of hard disk drives range from 20 megabytes on up.
Additional units of measurement include the gigabyte, which is 1,024 megabytes or about 1,000,000,000 bytes, and the terabyte, which is 1,024 gigabytes or about 1,000,000,000,000 bytes. These units of measurement, of course, are larger than you'll find commonly used in the PC world.
Random Access Memory (RAM)
Before you can use a computer program, it must be loaded into the computer's RAM memory, so the first use of RAM is for holding programs while they're in use. This is not a difficult process; in the case of Lotus 1-2-3, you type the word lotus at the DOS prompt, and DOS loads the 1-2-3 software from the disk drive to the RAM memory. This process takes a moment to complete, and that's why there's a delay between the time you type the command to start a program and when you can actually start using the program.
A second use of RAM memory is for holding what's commonly called working data. Many programs store their data in RAM while they're working with it. In the case of Lotus 1-2-3, for example, the worksheet must reside entirely in RAM while you're working with it, so the amount of RAM you have installed determines how large a worksheet you can build. But some programs--WordPerfect and many database programs, for example--use a hybrid approach, where working data is stored both in RAM and on the disk.
There are two reasons why programs and data must be in RAM before they can be used. First, RAM is must faster than disk storage, on the order of perhaps 200,000 times as fast. Disk storage is simply too slow for use as the main storage in a computer. Second, the processor can't access data directly from the disk due to the way disk storage is organized. Data or programs must be in RAM for the processor to access them.
Composed of electronic RAM chips
To add more RAM to your computer, just buy more RAM chips and plug them in. You may, however, need to purchase a memory expansion board, which provides the space to install more RAM.
High-speed access to data
When data is located in RAM, the processor has nearly instantaneous access to it. That's the most important characteristic of RAM, and why many programs store working data there.
Volatile -- loses contents with power loss
That's the drawback to RAM--if you create data in RAM, you must at some time save it to a disk, or when you turn off the computer (or even quit using the program that created the data), it is lost.
Limit of Conventional Memory: 640 KB
This limitation is due to the design of the Intel 8088 and 8086 microprocessors, as well as design limitations of the current versions of DOS, the computer's operating system that manages the RAM. The 80286, 80386, and 80486 processors can address more memory, but in a different fashion than they address conventional memory.
Extended Memory
Extended memory (often abbreciated XMS) was first introduced with the IBM PC AT in 1984, and is available only on 80286, 80386, or 80486-based computers. Extended memory is one type of memory above the regular DOS limit of 640 KB. Most computers that support extended memory can have up to 16 MB extended memory.
Extended memory is not compatible with classic DOS software, as extended memory is available only when the processor is operating in protected mode, and classic DOS is meant for real mode. Microsoft Windows 3.0 can run in protected mode, and OS/2 always runs in protected mode. There are some other software programs that require extended memory, and support for extended memory is becoming more popular.
Today, many AT and 386-type computers come standard with one to four megabytes of RAM, typically allocated as 640 KB regular DOS memory, and the remainder as extended memory.
Expanded Memory
Expanded memory was created by Lotus, Intel, and Microsoft (and is often called LIM expanded memory or abbreviatred EMS) in 1984. It is available on all IBM compatible computers from the original PC through the PS/2 models. AST later created a more advanced version of expanded memory called Enhanced Expanded Memory, or EEMS. The most recent version of the LIM standard (version 4.0) allows for 32 MB of expanded memory.
Classic DOS programs can use expanded memory if they are modified to include support for this memory. The modification is relatively easy for software publishers to make, and by now nearly all programs that could make use of a lot of memory support expanded memory. Remember, the software must support expanded memory to use it. Lotus 1-2-3 Release 1A didn't support expanded memory, but the later Release 2.0 did.
Expanded memory is often the most useful type of extra memory for the average PC user. 386-based computers can make their extended memory appear to be expanded memory through the use of a software driver. This software often is supplied with the computer, as in the case of the EMM386.SYS driver included with DOS 5.0 and Compaq's CEMM driver, or may be purchased, as with Quarterdeck's excellent QEMM software. 286-based computers don't have as much flexibility in allocating their memory as the 386-based computers do.
Early on, EMS was much more popular than XMS. One reason was that few people at that time had a computer with an 80286 processor, so they couldn't have XMS. Now, as 80286 and 80386 computers are commonplace, the shift is towards XMS. Memory management is one of the most frustrating aspects of IBM PC-type of computers, as many people have software programs that want XMS memory, but others that want EMS.
Diskette Drives, Hard Disk Drives, Network Drives
|
Floppy Diskette Drive |
Hard Disk Drive |
Network Drive |
|
Removable; infinitely expandable; secure |
Fixed; normally a built-in, permanent part of the computer |
Remote; is in the network server and accessed through the network cabling. |
|
Small capacity |
Large capacity |
Usually huge capacity |
|
Slow access time and data transfer |
5 to 20 times as fast |
The drive itself is usually very high speed, but the effective speed for the users is faster than a floppy drive, but usually not quite as fast as a local hard drive |
|
Individual user usually must make backups |
Individual user usually must make backups |
Network administrator usually makes backups |
Since a floppy diskette is removable, if one diskette is full, you can use another diskette. If the hard disk drive becomes full, you'll have to erase old files from the disk to free space. Or, you can add another hard drive--many computers can hold more than one.
Since the hard drive is built in the computer and not removable, if someone can gain access to your computer, they can access (and alter) your data. But you can secure data stored on a floppy diskette in the same way you'd secure valuable or confidential papers--take it with you or lock it up. Additionally, data stored on a floppy diskette is portable.
A 10 megabyte hard disk drive is equivalent to about 30 360 KB floppy diskettes. This tremendous advantage in storage capacity is the primary feature of a hard disk drive that makes it so valuable to many people.
IBM PC and XT computers (and compatible computers) use a 5.25" double-sided double-density diskette that holds 360 KB. IBM AT computers and compatible computers, as well as most 80386 computers use a 5.25" double-sided high-density diskette that holds 1.2 MB. Generally, the 1.2 MB drives can read and write diskettes in the 360 KB format. The reverse is not always true--diskettes created in the 360 KB format on a high-density diskette drive can't always be read by an older 360 KB drive.
The 3.5" diskette drives are available in two formats: 720 KB and 1.44 MB. IBM PS/2 Model 25 and 30 computers use the 720 KB format, while models greater than 30 use the 1.44 MB format.
The average access time of a disk drive, which is the average time it takes to locate a piece of data, is the most important measurement of a drive's performance. Floppy diskette drives typically have access times of 300 to 500 milliseconds. Hard disk drives of the type found in an IBM PC XT or compatibles have average access times of 70 to 100 milliseconds, and the average access time of a hard drive that would be found in an IBM PC AT or compatible computer is 40 milliseconds or less.
Additionally, the data transfer rate, which is the rate at which the drive can exchange data with the computer, is several times greater for a hard disk drive.
History of PC DOS
Version 1.0 of DOS supported the features of the original IBM PC. That computer used single-sided floppy diskette drives, meaning that the drive worked with just one side of the diskette. Later, manufacturers introduced double-sided diskettes, which doubled the capacity of a disk. But the existing version of DOS didn't know how to work a double-sided drive, so a new version of DOS was needed.
Version 2.0 of PC DOS included support of a hard disk drive, as well as the various commands needed to effectively use the hard drive--the commands to use subdirectories and the backup and restore commands. Later, IBM introduced version 2.1, which included minor revisions for the PC Portable and PC Junior.
Version 3.0 supported the 80286 processor found in the AT, the 1.2 MB high-density floppy diskettes, and large capacity hard disks. Version 3.1 supported the IBM PC Network. Version 3.2 made it possible to use the 3.5 inch, 720 KB floppy diskette drives on an IBM PC. Version 3.3 is necessary to support the PS/2 line of computers from IBM, and 3.5" 1.44 MB diskette drives.
Version 4 of DOS provides support for disk volumes greater than 32 MB. Previously, most versions of DOS supported a maximum drive size of 32 MB. A user of a 40 MB drive, then, must partition the drive into two or more smaller volumes, perhaps a drive C of 32 MB and a drive D of 8 MB. DOS 4, however, can make the entire disk, even hundreds of megabytes in size, be drive C. Also, version 4 contains a shell program that provides a menu for running programs and performing DOS file commands.
Version 5.0 added many new features, such as improved memory management, a new shell program, commands to undelete files and unformat disks, help for DOS commands, an improved editor to replace edlin, and many other small refinements.
OS/2
OS/2 is the newest operating system from IBM and Microsoft. It's not an upgrade in the sense that DOS 5.0 is like DOS 4.0 with some new features. Instead, OS/2 is a separate operating system that offers many new features. OS/2 requires a PC with 80286 or 80386 processor, hard drive, and at least 1.5 MB memory. OS/2 operates in the 80286 and 80386 processor's protected mode, meaning that it can address up to 16 MB of RAM memory. OS/2 implements virtual memory, which is a way of simulating more memory than the computer actually has through disk swapping. OS/2 also offers multitasking execution of programs, meaning that multiple programs can be running at the same time.
Classic DOS applications do not take advantage of OS/2's capabilities, although OS/2 does offer a compatibility box that will run most classic DOS applications. The compatibility box, however, does not support OS/2's advanced features, and not all DOS software will work properly in the compatibility box. Software publishers that intend to sell OS/2 versions of their products must rewrite them, often from the beginning.
IBM, I think, is puzzled as to why OS/2 isn't more popular. Currently, DOS outsells OS/2 by a wide margin, and some software publishers have abandoned or deemphasised OS/2 development projects.
Microsoft Windows
Microsoft Windows, especially the version 3.0 that was released in May of 1990, is an immensely popular software program that isn't an operating system in itself, but works along with DOS to give the operating system new capabilities. Programs written to the Windows 3.0 standard have a common look and feel that makes them consistent with each other, they can share data either through cut-and-paste or through dynamic data exchange, they can access large amounts of memory under Window's control, and they can multitask, meaning you can load several programs at the same time.
Some of the specific features of Windows include:
The ability to run several applications at the same time, and to switch between them quickly. This means that you can keep a word processing program, a spreadsheet program, a graphics program, and perhaps several other programs active at the same time.
The ability to transfer information from one application to another. The transfer may be a simple cut-and-paste operation, or it might be more sophisticated. For example, both Microsoft Excel (a spreadsheet program) and Microsoft Word for Windows) a word processing program) support Dynamic Data Exchange (DDE). This means that you can paste a link to an Excel spreadsheet in a Word document. As you make changes to the spreadsheet, Windows updates the word processing document as well.
A consistent look and feel to applications. One common complaint about IBM and compatible personal computers is that different software programs work in different ways. For example, in WordPerfect you press function key F10 to save a document. In Lotus 1-2-3, you type /fs. Other programs use even different commands. Windows applications, on the other hand, generally follow certain conventions. Most Windows applications will have a command called Save located on the File menu. Once you learn to use one Windows application, then, others are usually easier to learn.
A What You See Is What You Get (WYSIWYG) mode of operation. If you format text to be larger, a different font, or italics, you'll generally see these effects on the screen before you print.
Effective memory management. Using traditional DOS, software applications make use of conventional memory, while some may require or make use of expanded or extended memory. Some of your applications may want expanded memory, while others may want extended memory. Windows, however, can manage your computer's memory efficiently and supply applications with the memory they need.
The current version of Windows is version 3.0. Previous versions of Windows, the 2.x series, are very different from version 3.0.
Currently, Microsoft sells hundreds of thousands of copies of Windows each month, and many software publishers have released Windows-specific products, or are actively working to adapt their DOS products to Windows versions.
Functions of DOS
"First breath of life"
Allows DOS is the most fundamental software program your computer uses; you'll have to use DOS before you get the chance to use software like Lotus 1-2-3, WordPerfect, or any other program. In this respect, we sometimes refer to DOS as a master supervisor or control program. It provides the foundation that allows applications programs (word processing, spreadsheet, database) to run. DOS is called a systems program, as opposed to applications programs like spreadsheets, word processors, and database programs.
Services
DOS also provides services to applications programs, helping applications programs with memory, disks, and peripherals, although you're not generally aware of this aspect of DOS. For example, when saving a file with Lotus 1-2-3, the 1-2-3 software doesn't actually perform the saving of data to the disk. Instead, 1-2-3 makes a request to DOS, saying "save this information on that disk drive using this name." DOS takes over and does all the work involved in finding space on the disk for the data, and writing the data to disk.
Administrative and utility
DOS also provides a set of utility commands which let you enter the date and time, format diskettes, copy files, and perform other administrative and maintenance tasks. This is the role of DOS that most people are familiar with, and it's these commands that you need to master in order to make effective use of your computer.
Loaded into RAM at startup
DOS, like all computer software, must reside in the computer's RAM memory before it is useful. This process, often called booting the computer, is one of the first tasks your computer performs after you turn it on. If your computer doesn't have a hard disk drive, the computer loads DOS from a diskette in drive A. Otherwise, it loads DOS from the hard disk drive C. DOS remains in the computer's RAM memory until you turn it off or perform a reboot or system reset.
At any time, you can force the computer to perform a reboot or system reset, which means that the computer resets itself, clears the memory, and loads a new copy of DOS from the disk. You perform a reset by holding down the Control and Alternate keys, and pressing Delete (some computers also have a switch or button for this purpose). A reboot is sometimes necessary when the computer freezes or locks up due to an error or bug in a computer program, but you shouldn't reboot unless a situation like this arises.
DOS command are divided into two classes: internal and external commands. The internal commands are loaded into RAM when the computer loads DOS; therefore, they're always available. External commands remain on the disk and are loaded into RAM memory when needed.
IBM did not develop DOS itself. Instead, IBM licenses DOS from Microsoft. (An exception is version 4, which IBM and Microsoft developed independently.) Microsoft's product is called MS DOS; IBM calls it PC DOS. Basically, they are the same. Other compatible computer makers may supply MS DOS with their computers; some others license MS DOS from Microsoft as IBM does but call it Compaq DOS or AT&T DOS. It's the same thing.
DOS Prompt
Finished with last task, ready for new command
It's the appearance of the DOS prompt that indicates the previous command is finished, and that you can type another command.
Default disk drive
A:\>
C:\>
The default disk drive means that if you tell DOS to perform a command involving a disk drive, and you don't specify in that command which disk drive to work with, DOS works with the default drive as the prompt indicates. Much of the time this rule of the default saves time and effort, but it can occasionally cause confusion or harm.
Changing the default disk drive
To change the default disk drive, type the name of the new default drive and the press the Enter key (remember disk drive names are followed by a colon). If C:\> is showing, typing
C:\>a:
produces A:\> as the DOS prompt, and drive A is the default disk drive.
Changing the default disk drive is useful when you want to perform several commands involving a disk drive other than the default. Changing the default in this case will make the command easier to type, and less likely to contain errors.
Changing the prompt
By using the prompt command, you can produce a more informative prompt.
C>prompt $p$g
C:\>
C:\LOTUS>
The prompt command has many options that let you customize the plain prompt that DOS normally supplies. The above command, prompt $p$g, produces a prompt that shows not only the default disk drive, but also shows the current directory of the disk.
Using Help
DOS 5.0 contains a new help feature that you might find useful. The first way to use help is to use this command:
C:\>help
You'll get a listing of the common DOS commands. After deciding on the command you need, you might type
C:\>help dir
or
C:\>help copy
to get help about the dir and copy commands. You can also add /? to any command to get help about it, as in
C:\>dir /?
This will display the same help information about the dir command that the command help dir does.
Format Command
Initializes disks for use on an IBM PC or compatible computer
A disk, floppy or hard, is organized into tracks and sectors. Tracks are concentric circles on the disk, somewhat similar to the groove on a phonograph record. Sectors are portions of a track. The IBM PC and XT floppy diskettes use nine sectors per track. The format command's job is to lay down the tracks and sectors on the disk. Later, programs like Lotus 1-2-3 will fill the tracks and sectors with their data. Until the disk is formatted, it can't be used, so it's an essential first step, and usually performed just once on each disk.
Erasing data is a by-product of the format command that can sometimes lead to lost data. It's important to understand the format command to ensure that you always format the correct disk.
Quality control check
As the format command performs its work, it tests the disk surface. If it finds defects, it marks that part of the disk as a bad track or sector, and will not use that part of the disk for data storage. At the end of the command, format reports if it found bad tracks and sectors.
Dangers and precautions
The most dangerous aspect of the format command is that it erases the data on the disk as it formats. Actually, this is not as true as it was in previous versions of DOS. In DOS 5.0, the format command by default performs a safe format. You can recover from a safe format by using the unformat command before you store any new files on the formatted disk. By using the format command with the /u switch, however, you can have DOS perform an unconditional format, which destroys the existing information on the disk. Even then, the mirror command may be able to recover some of the information.
Switches
C:\>format a: (the default, performs a safe format of drive A)
C:\>format a: /u (performs an unconditional format of drive A)
C:\>format a: /s (produces bootable system disk)
Switches to the format command cause it to behave in different ways. The /s switch tells the format command to copy the essential DOS system files to the formatted disk, thus creating a disk that you can use to boot the computer from. This is not done very often, as most people boot the computer from the hard disk drive, and making a system disk reduces the capacity of the disk. It is a good idea, however, to keep one disk formatted this way, as you'll be able to boot your computer if the hard drive isn't working. The /u switch performs an unconditional format. You can use the /f switch to specify the disk capacity when formatting. The two most common format commands with this switch are:
C:\>format a: /f:360
C:\>format a: /f:720
The first command formats a double-side, double-density (360K) disk in a high-capacity, AT-style drive. The second formats a double-sided, double-density (720K) disk in a high-capacity drive.
Unformatting A Disk
If you formatted a disk with the safe format, you can recover the information that was on the disk. DOS 5.0 by default performs a safe format; to perform an unconditional format you must use the /u switch. The command you need to use looks like this:
C:\>unformat a:
Files
All data on the disk is stored in a file. In this sense, the file is a logical unit of organization of the disk. Of course, the disk is physically organized as tracks and sectors, but you're never aware of what track or sector a file is stored in, just the file name under which it is stored.
Any file could be a spreadsheet file, word processing document file, database file, or a file created by some other type of program. Generally, with most programs, each time you create a new spreadsheet, word processing document, or database, and save it to the disk, you've created a new file on the disk.
File Names
"Root" name
Eight characters maximum length
Alphabet characters (capitalization doesn't matter)
Digits 0 Through 9
$ & # @ ! % ' ` ( ) - _ { }
No spaces!
Since the rules for which punctuation characters may be used is highly arbitrary, a simple rule to remember is use just the letters of the alphabet and the digits. You'll sacrifice some flexibility in naming your files, but the rule is easier to remember. Why can't you use spaces? Because in DOS commands, spaces are used to separate one file from another, and if a file has a space in its name, DOS thinks you typed two file names.
Also, many programs restrict the allowable file name characters. For example, in dBase III Plus, a database file name must start with a letter, and can contain letters, digits, and the underscore, but nothing else. This information comes from each program's manual, which is always a valuable resource.
Extension (optional)
Three characters maximum length
Same allowable characters as the root name
Separated from root name by a period when used in a command
Often used to indicate file type: .BAS BASIC language program, .COM, .EXE Executable computer program, .BAT DOS batch file, .WKS, .WK1, .WK3 Lotus 1-2-3 worksheet files, .DBF dBase III Plus database, .DOC Microsoft Word document file. The use of the extension as a type indicator is very valuable, providing the ability to work with groups of files with single commands.
Directory (dir) Command
Displays list of files
The directory command produces five columns of information. The first column is the root name of the file. The second column is the file's extension, if it has one. Next, DOS displays the file's size in bytes. Finally, DOS shows the date and time the file was last saved or modified. At the end of the listing, DOS shows the number of files on disk and the free disk space remaining.
C:\>dir
This command displays the directory of drive C (the default drive). Since we didn't specify which disk to take the directory of, DOS looked at the default drive. If DOS is displaying the C:\> prompt, typing dir produces the list of files on drive C, the hard disk drive.
C:\>dir a:
Displays directory of drive A. In this case, we specified a disk drive for the directory command to work with, so we get a list of files on drive A.
C:\>dir command.com
This command displays directory information for the file command.com (if it exists on drive C). If the dir command doesn't find the specified file, it reports "File Not Found."
C:\>dir a:command.com
Displays directory information for the file command.com (if it exists on drive A). Adding a disk drive name as a prefix to a file name forces DOS to work with that disk drive, rather than working with the default disk drive.
Switches
C:\>dir /p
C:\>dir /w
C:\>dir /w /p
These two switches are necessary because unlike a word processing or spreadsheet program, the dir command doesn't let you press the Page up key to see previous screens of files. Using the /p switch shows the same information as the regular dir command, but one screen at a time. The /w switch shows just the filename and extension.
The dir command also works with the wildcard file name characters. To view all the Lotus 1-2-3 worksheets on a disk, type dir *.wk1. To use these switches with a file name, remember to type the command switches last. For example:
C:\>dir *.wk1 /p
This command displays all the Lotus 1-2-3 worksheet files, pausing after each screen.
C:\>dir /s
The /s switch tells the dir command to display the files in the current directory as usual, but then show the files in the current directory's subdirectories. If you're in the root directory when you issue this command, you'll display all files on the disk.
C:\>dir /o
The /o switch, followed by one or more letters, sorts the directory listing. The letters you can follow the o with include n for alphabetically by name, e for alphabetically by extension, d for date and time (earliest first), s for smallest size first, and g for directories placed before files. For example, the command dir /oe sorts by extension. You can use more than one sort letter, as in the command dir /oen which sorts by extension, then by name within the same extension. To sort in reverse order, place a minus sign before the letter, as in dir /o-n, which sorts by name, but in reverse alphabetical order.
Copy Command
Copies a file or group of files
Copy <source> <target>
In the general format of a computer command, words in the <> characters mean that you replace that word with the actual value you want to use. In the copy command, then, you type the word copy, a space, the name of the file to copy from (the source of the copy), a space, and the name of the disk drive or file to copy to (the target or destination of the copy).
C:\>copy command.com a:
This command copies the file command.com from drive C to drive B, retaining the same name. When the target of a copy is just the name of a disk drive or directory, the resulting copy of the file on the target disk has the same name as the source file.
C:\>copy command.com bill.com
This command copies the file command.com from drive C to drive C, with the new name bill.com. This form of the copy command is not commonly used, but it illustrates the meaning of the source of the copy and the target. Why is the file bill.com created on disk drive C? Because drive C is the default drive (because of the C:\> prompt), and the command mentions nothing about any other disk drive, so DOS uses the default drive.
C:\>copy command.com a:bill.com
This command copies the file command.com from drive C to drive A, with the new name bill.com. Again, an uncommon example, but it shows how you can add a disk drive identifier to a file name to force it to a different disk drive than the default.
C:\>copy a:command.com c:
This command copies the file command.com from drive A to drive C, retaining the same name. This copy command illustrates that DOS can copy from any disk to any other disk.
C:\>copy a:command.com
This command copies the file command.com from drive A to drive C, retaining the same name. The difference between this command and the preceding command is that we omitted the target of the copy. In this case, the rule of the default applies, and the target becomes drive C because of the C:\> prompt.
Copying Over Existing Files
What if the file being copied already exists on the target drive? Since file names must be unique, DOS can't place two copies of the file on the disk in the same directory. Instead, DOS first erases the file from the target disk, and then makes the copy. This is the only time that the copy command will erase a file to make room for a copy--when copying a file with the same name as one on the target disk. Otherwise, if the target disk doesn't have enough room for the incoming file, copy reports "Insufficient Disk Space" and halts the copy command.
Be careful with the copy command, as it can lead to loss of data as DOS deletes an existing file to make way for a file being copied with the same name. Typically, when copying a file to a disk for the second time, you're copying a new version over an old version. In this case, you do want the copy command to delete the existing, older version of the file. But if you mistakenly copy the old version to a disk or directory containing a newer version of the file, you'll lose the new version and retain just the old version. You'll lose the changes you made to the new version.
Moving Files
DOS doesn't have a move command. To move a file from one disk to another, or from one subdirectory to another, first copy it, then erase it.
Global File Names
DOS provides two special characters, called wild card or global characters, which make it easy to manipulate groups of files with a single command.
? (Question Mark)
The question mark matches any single character. Budget?.wk1 matches budget1.wk1, budget2.wk1, budgetx.wk1
* (Asterisk)
The asterisk matches any number of any characters. Budget.* matches budget.wk1, budget.dbf, budget.doc, and budget.bas. *.wk1 matches budget.wk1, project.wk1, bill.wk1, and susan.wk1. (Since Lotus 1-2-3 worksheet files almost always have the file extension .wk1, *.wk1 matches all Lotus 1-2-3 worksheet files.) *.* matches all files.
C:\>copy *.wk1 a:
This command copies all files with the extension .wk1 (these are Lotus 1-2-3 release 2 or 2.2 worksheets) to drive A, retaining the same names.
C:\>copy *.* a:
This command copies all files from drive C to drive A, retaining the same names.
C:\>copy *.* a
The target of this copy command (the letter a) looks like a disk drive name, but since it isn't followed by a colon, it's interpreted as a file name. In this case, the file's name is "a" located on drive C. Each of the files on drive C is copied to this file, with each new file being copied replacing the existing file. Therefore, after the copy command is complete, the file called "a" on drive C is identical to the last file copied. Be careful with this--if your goal is to copy files to the floppy disk drive and then delete them from drive C, you could lose some data.
Most programs supply their own file name extensions: .wks for Lotus 1-2-3 Release 1A, .wk1 for Lotus 1-2-3 Release 2 and 2.2, .wk3 for Lotus 1-2-3 Release 3, .doc for both Microsoft Word and MultiMate, .dbf for a dBase III Plus database file, .com and .exe for executable computer program files, .bat for DOS batch files, and many other examples. By using these file extensions along with the wildcard or global characters, it's easy to manipulate groups of files with a single command.
Other DOS commands that work with global file names include the dir command, as in dir *.wk1, which lists all the Lotus 1-2-3 worksheets, and the del or erase command, as in del *.wk1, which deletes all the Lotus 1-2-3 worksheets.
Erase or Del Command
Erase files and frees disk space
The space formerly occupied by the erased file is considered unused space on the disk, and other files will use its space.
C:\>erase budget.wk1
C:\>del budget.wk1
These commands erase the file budget.wk1 from drive C, the default disk drive. In these commands, we didn't indicate which disk drive to erase the file from, so DOS looked for it on the default drive (C, because the prompt is C:\>).
C:\>erase a:budget.wk1
This command erases the file budget.wk1 from drive A. In this command, we added the disk drive name to the file, so the command looks to that disk drive for the file to erase.
C:\>erase *.wk1
This command erases all files from the default drive C with the extension .wk1. This command illustrates the use of a global file name to erase a group of files with one command. Be careful with a command like this, as it may erase more files than you planned to erase.
C:\>erase a:*.wk1
This command erases all files from drive A with the extension .wk1. This command uses a global file name again, but uses a disk drive name as a prefix to the file name, so the command erases files from drive B.
C:\>erase a:*.*
This command erases all files from drive A (requires confirmation). Again, using a drive name and a global file name to erase all the files from drive B. DOS does force you to confirm that you really want to perform this action.
Also known as del
You can use either word--erase or del--to perform exactly the same command.
An interesting note is that the erase command doesn't actually erase the data from the surface of the disk in the way that an eraser removes written words from a sheet of paper. Instead, DOS simply marks the file as erased and allocates its space on the disk to the free space on the disk. Until another file overwrites the erased file's data, it is recoverable. DOS 5.0 contains a new command called undelete to recover erased files. Many utility software packages (the most famous example is the Norton Utilities) offer this feature as well.
Since the erase command doesn't remove data from the disk, there may be security issues involved in some instances, as files you thought were erase can be recovered and accessed by others. Some utility programs, such as Norton's, include a program to overwrite the erased data with meaningless characters, so that even if someone recovers the file, the original data is gone.
Undeleting Files
DOS 5.0 contains a command to recover erased files. This command works because DOS doesn't erase a file by rubbing an electronic eraser over the disk; it merely marks a file as erased so it knows that the erased file's space is usable. Until that space is actually used, the file might be recoverable.
Use the undelete command in this manner:
C:\>undelete budget.wk1
This command will attempt to undelete a file called budget.wk1.
Undeleting works in two ways. You can install the mirror deletion tracking program, or you can not use it. The undelete command works best when deletion tracking is used. Without it, you can still undelete files, but the process might not work as well. One difference is that when not using deletion tracking, you'll need to supply the first letter of a file's name:
C:\>undelete autoexec.bat
Directory: C:\
File Specifications: AUTOEXEC.BAT
Deletion-tracking file not found.
MS-DOS directory contains 1 deleted files.
Of those, 1 files may be recovered.
Using the MS-DOS directory.
?UTOEXEC BAT 126 7-29-91 4:29p ...A Undelete (Y/N)?y
Please type the first character for ?UTOEXEC.BAT: a
File successfully undeleted.
The most important thing to remember about undeleting files is that you must use the undelete command immediately after you discover the accidental deletion. Otherwise, the command may not work.
Renaming a File
C:\>rename budget.wk1 budget1.wk1
This command renames the file budget.wk1 on drive C to budget1.wk1 on drive C. The first file name is the name of the old file, and the second name is the new name to use.
Rename does as its name says--it changes the name of the file. The command copy budget.wk1 budget1.wk1 is different, as it creates a new file called budget1.wk1 as does the rename command, but it leaves the original file budget.wk1 alone. After this copy command, then, you'll have two files on the disk with the same contents, but different names. The rename command, though, leaves just one file on the disk, the new file budget1.wk1. The original file, budget.wk1, is gone.
C:\>rename *.txt *.doc
This command renames all files in drive C with the extension .txt to files on drive C with the same root names, but with the extension .doc. This command shows that wild card or global files names work with the rename command.
C:\>rename a:budget.wk1 budget1.wk1
This command renames the file budget.wk1 on the A drive to budget1.wk1 on the A drive. The resulting file, budget1.wk1, is placed on drive A, even though we didn't specify a drive for the new file and the default drive is C. In other words, you can only rename a file on the same disk drive or directory as it already exists--no crossing drives. Also, if the new name already exists, rename displays an error message and doesn't make the name change.
Editing DOS Commands
DOS 5.0 contains a new command called doskey. By using this command, you can easily recall and edit previous commands you've entered. To install doskey, use this command:
C:\>doskey
This command needs to be entered each time you reset your computer, so it's a good candidate for placement in the autoexec.bat file.
After doskey is installed, it maintains a history of commands you've entered. By pressing the Up arrow key, you can recall these commands. For example, if you want to repeat a command that you've issued earlier, press the Up arrow key until the command reappears. Then, press the Enter key to actually execute the command.
You can also edit an existing command in this way: Use Up arrow to redisplay the command. Then, use Left and Right arrow to move across the command line. The Delete key deletes the current character. You can type over existing characters, or by pressing the Insert key, you can move into insert mode and insert new characters. The Esc key clears a command from the screen.
Exercise 1
Complete these paper exercises by writing down the answers. Your instructor will discuss the answers after everyone completes the questions.
For these questions, assume these facts unless otherwise stated: A floppy diskette in drive A contains Lotus 1-2-3 worksheet files (with the extension .wk1), WordPerfect files (extension .wp), and dBase database files (extension .dbf). The computer has a hard drive C, and the prompt is C:\>.
1. List all files on drive C, screen-by-screen.
2. List all files on drive A in a wide format.
3. List all the Lotus 1-2-3 worksheet files on drive A, page-by-page.
4. Copy the Lotus 1-2-3 worksheet BUDGET1 from drive A to drive C.
5. Copy the Lotus 1-2-3 worksheet BUDGET1 from drive A to drive C, renaming it 1988B in the process.
6. Copy all WordPerfect documents from drive A to drive C.
7. Correspondence produced for John Doe has the extension .jd. Copy his files from drive A to drive C.
8. There is a series of Lotus 1-2-3 worksheet files on drive A called BUDGET followed by a single numeric digit (BUDGET1, BUDGET2, etc..) Copy all of them from drive A to drive C.
9. Copy all files from drive A to drive C.
10. Rename the Lotus 1-2-3 worksheet file on drive C from 1988B to BUDGET.
11. Delete the Lotus 1-2-3 worksheet file BUDGET on Drive C.
12. Delete all the dBase database files from drive A.
13. Delete all files from drive A.
14. Whoops, the wrong disk was in drive A for the previous question. What would you do?
Directories and Subdirectories
Directories organize a hard disk drive
Since a hard drive's tremendous capacity lets you create hundreds or even thousands of files, it's necessary to subdivide the disk into more conveniently manageable units. These organizational units are directories, sometimes called subdirectories. When you have created directories, you can later change to one of the directories, and DOS "sees" only the files contained in that directory. Even if thousands of files exist in other directories, you can work with just those files in the current directory that you changed to. For example, typing del * .* will erase only those files in the current directory. In many ways, it's as though each directory was a separate disk drive.
Hierarchical structure
The directories on a disk are organized hierarchically, with one directory at the top of the directory structure, called the root directory. (This directory, called "root" when spoken, is typed is the \ [backslash] character on the keyboard.) All other directories are below or subordinate to the root directory--thus the term subdirectory. DOS creates the root directory automatically when you format a disk.
Organized by software program, function, or other scheme
When you decide to use directories, you need to make your own directory structure with the make directory command. Many people create a directory for each program they use, perhaps one for their Lotus 1-2-3 work, a second directory for dBase III Plus, and a third for Microsoft Word. Others create directories along project or function lines, perhaps a directory for work relating to budgets (which could contain Lotus worksheets, dBase databases, and word processing files) and another for proposal files of all types.
|----- home
|
|----- lotus -----|----- work
| |
| |----- school
\ --------|----- dbase
| |----- home
| |
|----- word -----|----- work
|
|----- school
In the shell, these directories will look like this:
In the shell, it's possible to collapse directories, in which case the same directory structure would look like this:
Directory Tree
¦ [-] A:\
¦ +-[ ] DBASE
¦ +-[+] LOTUS
¦ +-[+] WORD
The + sign means that this directory contains subdirectories that aren't being displayed at the moment. Since the \dbase directory doesn't have the + sign, it means that there are no subdirectories in this directory.
Paths
Each directory is identified by its path, which is a listing of all directory names you have to traverse to get to the desired directory.
\lotus
This path starts at the root directory (the \ character) and then proceeds to the directory called lotus within the root directory.
\lotus\home
This path starts at the root directory, proceeds to the lotus directory, and then proceeds to the home directory within the lotus directory. Note that this command uses two \ characters. The first one means start at the root directory, while the second \ serves to separate the name lotus from the name home. Thus, the same character has two different meanings in the same command.
\lotus\home\budget.wk1
This represents a file called budget.wk1 located in the \lotus\home directory. Notice that the backslash character also serves to separate the file name from its directory name.
c:\lotus\home\budget.wk1
This represents the most complete specification of a file. It specifies the disk drive name, the path to the directory that the file is located within, and the name of the file. Since this file name includes all these items, it is completely unambiguous.
Working With Directories
Once you've created directories, you need to know how to reference a file in a directory when using DOS commands like copy and del or erase.
Change to the directory
One strategy in working with files in directories is to first change to the directory of interest. Once you change to a directory, you can reference or access files just as if there were no directories.
C:\>cd \lotus
C:\LOTUS>copy budget.wk1 a:
C:\LOTUS>del budget.wk1
The firsttwo commands copy a file called budget.wk1 that was located in the \lotus directory to disk drive A. The first command makes the \lotus directory the current directory. (Note that the enhanced DOS prompt changes to show the path of the current directory.) Then, the second command makes the copy. Note that the second command makes no reference to the \lotus directory at all, and in fact, it ignores the fact that there are subdirectories on the disk. It illustrates that once you change to the right directory, it's almost as if there weren't any directories at all. The third command deletes the file.
C:\>copy \lotus\budget.wk1 a:
C:\>del \lotus\budget.wk1
In these commands, we prefix the name of the file (budget.wk1) with the path to the directory the file is located in (\lotus). This means that this command works no matter which directory is the current directory, while the simple command copy budget.wk1 a: requires that you change to the \lotus directory first. Notice that this command uses two \ characters. The first one means start the path at the root directory, while the second serves as a separator character between the name of the directory lotus and the name of the file budget.wk1.
C:\>cd \lotus
C:\LOTUS>copy budget.wk1 \word
These two commands copy the file budget.wk1 from the \lotus directory to the \word directory. The first command, as we've seen, makes the \lotus directory current. The second command copies the file budget.wk1 from the current directory to the word directory. This shows that instead of using a disk drive name such as a: for the target of a copy, you can use a path to a directory as the target.
C:\>cd \word
C:\WORD>copy a:*.doc
These commands copy all the Microsoft Word files (they end with the extension .doc) from drive A to the \word directory on drive C. The first command, of course, makes the \word directory the current directory. The second command uses the file specification a:*.doc as the source of the copy, which means all files on drive A with the extension .doc. What is the target of the copy? Since we left it blank, the target becomes the current directory of the default drive, which is c:\word.
As a more comprehensive example, suppose that in the c:\lotus directory there is a file called budget.wk1. Your goal is to copy it to the c:\word directory. Also, suppose that the current directory is c:\lotus. This command will perform the copy:
C:\LOTUS>copy budget.wk1 \word
Since the file budget.wk1 is in the current directory, we can reference it directly without a directory or drive prefix. Suppose the current directory is c:\word. You'd need this command:
C:\WORD>copy \lotus\budget.wk1
In this case, we have to prefix the name of the source file with the directory it's located in. We can leave the target of the copy blank, because the current directory is the target directory. Now, suppose that the current directory is neither the source or target:
C:\>copy \lotus\budget.wk1 \word
In this case, we must specify both the source and target directories. This command is a combination of the two previous commands. Finally, suppose that the current directory is a disk other than C:
A:\>copy c:\lotus\budget.wk1 c:\word
Here, we must add the disk drive identifier to the previous command. This command will work at all times, no matter what the current drive and directory is. The preceding commands make use of knowledge about the current drive and directory to shorten the command.
We've seen how to use the copy command to place files in directories. How else do files get in a certain directory? Nearly all software programs have a provision for placing their files in the desired directory. For example, in Lotus 1-2-3, when you save a file you can type a directory name before it, as in \lotus\home\budget, which would save the worksheet with the name budget, but in the \lotus\home directory. Alternatively, you could have used the /File Directory command in 1-2-3 to change 1-2-3's current directory to \lotus\home. Then if you save the worksheet with the simple name budget, it's placed in the \lotus\home directory. (You can use the /Worksheet Global Default Directory Update command to make this change permanent.) The equivalent command in Microsoft Word, for example, is Transfer Options. WordPerfect 5.1 uses the F5 List key for temporary changes to the default directory, or the Shift-F1 Setup key to make a permanent change.
Make Directory Command
Creates a Directory
Before you can work with directories, you must create them
C:\>md \lotus
This command makes a directory called \lotus underneath the \ (root) directory.
C:\>md \lotus\home
This command makes a directory called home underneath the \lotus directory.
|----- home
|
|----- lotus -----|----- work
| |
| |----- school
\ --------|----- dbase
| |----- home
| |
|----- word -----|----- work
|
|----- school
C:\>md \lotus
C:\>md \dbase
C:\>md word
The last command illustrates that you don't always need to use the \ character when naming directories. If you do use \, the new directory will be created directly below the root directory. If you don't use \ to start the name, the new directory is created in whichever directory was current when you issued the md command.
C:\>md \lotus\home
C:\>md \lotus\work
These two commands created new directories underneath or within the \lotus directory, called \lotus\home and \lotus\work.
C:\>cd \lotus
C:\>md school
These two commands create a new directory called \lotus\school. Note that since we used the cd (change directory) command to first change to the \lotus directory, it wasn't necessary to type anything besides the directory name school. If we had typed md \lotus\school, the command would have worked, of course, but that command supplies unnecessary, though harmless, information. If we had typed md \school, DOS would have created a directory called \school. This directory is located immediately below the root directory, instead of within the \lotus directory.
Exercise 2
Create this directory structure on the hard drive C:
|----- home
|
|----- ss -------|----- work
| |
| |----- school
\ --------|----- db
|
|
|----- wp
Change Directory Command
Changes to a directory
Once you change to a directory, you can access the files within that directory easily. Also, before you can run many computer programs, you must first change to the directory where that program is located.
C:\LOTUS>cd \
This command changes to the \ (root) directory.
C:\>cd \lotus
This command changes to the \lotus directory.
C:\>cd lotus
This command changes to the \lotus directory, if currently in the \ (root) directory. You must be within the root directory for this command to work, because that's where the \lotus directory is. If you're in the \word directory and you enter this command, it means to try to change to a directory called lotus that's contained within the \word directory (in other words, the directory \word\lotus). Since there is no such directory, the command fails, and DOS displays an error message.
C:\>cd \lotus\home
This command changes to the \lotus\home directory.
C:\LOTUS>cd home
This command changes to the \lotus\home directory, if currently within the \lotus directory. If you're not in the \lotus directory, say the root directory, this command won't work. That's because there is no directory in the root directory called home, and typing a directory name without the \ character means to find that directory within the current directory. If it isn't found, the command fails and DOS reports an error message.
C:\LOTUS>cd ..
Changes to the parent directory. Two periods (..) is the shorthand name for the parent directory. Typing this command enough times eventually returns you to the root directory, which is the eventual parent of all directories.
Remove Directory Command
Removes a Directory
To remove a directory, first, erase all files from the directory. The . and .. directories remain, as they can't be erased. Second, you must change to a different directory than the one you want to remove. Finally, issue the rd command.
DOS, as a safety measure, won't let you remove a directory until all the files in it are deleted. The two special housekeeping files, . and .., can't be erased, but the directory is considered empty if only those files remain. Also, you must change to a directory other than the one you plan to remove. DOS, in other words, won't let you pull the rug from under your own feet and remove the current directory.
C:\>rd \lotus
This command removes the \lotus directory. Once you've taken care of the above steps, you can use the rd command to remove the directory. At this time, the directory is gone, and it doesn't appear in the directory listing.
Exercise 3
Perform these exercises on your computer. When deleting files, please make absolutely sure that you're in the correct directory or have specified the correct path to the files you're deleting. Please ask your instructor to check any commands that you may not be sure of. There may be more than one method for completing many of the actions you are to perform. See if you can identify alternate ways of performing the actions.
For these questions, assume these facts unless otherwise stated: A floppy diskette in drive A contains Lotus 1-2-3 worksheet files (with the extension .wk1), WordPerfect files (extension .wp), and dBase database files (extension .dbf). The computer has a hard drive C, and the prompt is C:\>.
1. Copy all the Lotus 1-2-3 worksheet files from drive A to the \ss directory on drive C.
2. Copy all the WordPerfect data files from drive A to the \wp directory of drive C.
3. Copy all the dBase data files from drive A to the \db directory of drive C.
4. Copy the Lotus 1-2-3 files BUDGET? from the \ss directory to the \ss\work directory.
5. Erase the files that you just copied from the \ss directory.
6. Remove the \ss\home and \ss\school directories.
7. Delete all files from the \db directory and remove it.
8. Copy all the files from the \ss\work directory to the \ss directory and remove the \ss\work directory.
9. Create a new directory structure that looks like this:
|---- lotus
|
\ -------- data -- |
|
|---- wp
10. Copy all the files from the \ss directory to the new \data\lotus directory.
11. Copy all the files from the \wp directory to the new \data\wp directory.
12. Remove the old \ss and \wp directories.
Using MS-DOS Shell
The shell is a graphical, menu-driven program that you can use to work with DOS. Many times you'll find that using the shell is easier than using the command line, but there are still times when the command line is easier to use.
To start the shell, use this command:
C:\>dosshell
You'll see something like this:
The shell screen contains several important areas. You can move from area to area by pressing Tab (or Shift+Tab to move backwards), or if you have a mouse, you can click in the area you want to work with.
The directory tree area contains information about the directories or subdirectories found on this disk. A plus sign means that the directory contains other directories. A minus sign means that the directory can be collapsed. An arrow in front of a directory name means that the directory is the current directory. You can expand a directory by moving to it and pressing the + (plus sign) key. Collapse a directory by moving to it and pressing the - (minus sign) key. You can expand all levels by pressing the * (asterisk) key.
The file list area contains a list of the files that are in the current directory. By selecting a file or group of files, you can perform commands such as delete, copy, and so forth. You can customize the way the shell program displays these files.
The basic method for selecting a file is to move to the file and press the space bar, although there are faster ways of selecting large numbers of files.
The program list area contains other programs you can start from the shell, such as the command prompt (goes to a regular DOS prompt), the editor, QBasic, a programming language, and Disk Utilities, which presents a menu of utilities. Because Disk Utilities is in the [ ] characters, we know that selecting this item presents a new menu of commands. You can add your own items to the program list.
The menu bar, near the top of the screen, contains commands that you can perform. You can access the menu bar in several ways: First, you can press Alt or F10, then touch the highlighted letter in the command name. Or, use the left and right arrow keys to highlight the command, and then press the Enter key. With a mouse, you can point at the menu command name and click.
After selecting a command from the menu bar, you'll see a pull-down menu as with this menu from the File group of commands. You can now select one of these commands by highlighting it and pressing the Enter key, pressing the highlighted letter of the command's name, or pointing to it with the mouse and clicking.
Some of the commands will be dimmed or not visible. These commands are not available at this moment.
Commands followed by ellipsis (...) produce a dialog box when selected. A dialog box gives you an opportunity to specify additional information about the command you want to perform.
A diamond before the command name means that the command is active.
Some menu commands may be followed by keyboard shortcut equivalents. For example, the Copy command is followed by F8. This means that you can press function key F8 instead of selecting the Copy command from the File menu.
To cancel a menu command after you've started it, press Esc.
Selecting An Area
To select an area to work with, press the Tab key to move forwards, Shift+Tab to move backwards. The title bar of the area you've selected changes color. With a mouse, you can click in the area you want to work with.
Dialog Boxes
A dialog box contains areas where you can adjust settings for an operation. This example lets you control how files are displayed in the file list.
To move about a dialog box, press Tab or Shift+Tab. To select an item, such as the check box before Display hidden/system files or Descending order, press the space bar. Pressing space bar once turns the item on (the x appears), pressing it again turns it off (the x disappears).
For an item list such as Sort by:, press the space bar until the button moves to the option you want to be in effect.
For a text box, such as Name: near the top of the dialog box, type the new information that should appear. You can use the left and right arrow keys to move through the text box and edit the existing information.
Selecting Files
A basic operation in using the shell is to select files in the file list. You might select a file because you want to delete, move, or copy it.
One method of selecting a file is to move the highlighter to it and press Shift+F8. You'll see the word Add on the status bar. Now, you can move to a second file and select it by pressing the space bar. You can move to as many files as you like and press the space bar.
A second method is to hold down the Shift key as you move with the up or down arrow keys. This method extends the selection as you move, and is good for selecting files that are in sequence.
You can select all files by using the File Select All command. The File Deselect All command removes the selection from all files.
File Commands
These are the important commands on the File menu:
Search presents a dialog box where you can fill in a wild card file name. Shell then searches the entire disk for files matching the name. When it's finished, you can work with the matched files, pressing Esc when finished.
View File Contents displays the contents of the selected file. You can't make changes, but you can look.
Move and Copy let you move and copy the selected files. You fill in the destination in a dialog box.
Delete deletes the selected files after you confirm.
Rename lets you change the name of the selected file.
Create Directory makes a new directory or subdirectory in the current directory. Therefore, move to the parent directory before issuing this command.
Select All and Deselect All let you quickly select or deselect all the files in the file list.
Exit leaves the shell and returns to the command prompt.
Options Commands
These are the important commands from the Options menu:
Confirmation determines whether shell asks for confirmation before deleting files, or when performing a copy or move that overwrites a file on the destination. It's good to leave these items selected until you gain experience.
File Display Options presents a dialog box that lets you control the pattern that the displayed files match, whether to sort them, and whether to display hidden and system files
Show Information displays helpful information about the selected file, directory, and disk.
Display presents a menu of alternative display modes. Some of the modes, depending on your computer configuration, may show more than the standard 25 lines.
Colors lets you change shell's colors.
View Commands
By using the commands on this menu, you can control the display of areas. For example, the Dual File Lists command shows two file lists side-by-side.
Tree Commands
These commands control the display of directories in the directory list. Expand Branch shows the current directory's subdirectories, if any, while Collapse Branch collapses the directory display. Expand All shows all directories.
Help Commands
The help commands lead you to on-line information about the various shell commands.
You can also request help information at any time by pressing F1. This gives context-sensitive help, meaning that shell tries to present a help screen containing information relevant to your current situation.
Backup Command
Copies data from hard drive to floppy diskettes
Making backup copies of files on the hard drive is essential for the protection of your data, as there are many ways that you can lose data from the hard drive--accidental erasure or format, mechanical failure of the drive, fire, flood, theft, even power failures at the wrong moment can disturb data.
Why not use the copy command to make backups? The primary reason is that since your hard drive stores many times the data a floppy disk does, it won't be long before the copy command reports "Insufficient Disk Space" and the copy command stops. Then, there's no easy way to restart the copy command at the right place. Also, the copy command works with just a single directory at a time. You can't use the diskcopy command because it can't copy to or from the hard disk drive.
C:\>backup c:\ a:
Backs up files from \ (root) directory of drive C to drive A.
C:\>backup c: a:
Backs up from the current directory of drive C to drive A. In this command, since we didn't specify a directory as the source of the backup, just the drive name C, DOS backs up from whichever directory is current.
C:\>backup c:\ a: /s
Backs up files from the \ (root) directory of drive C, plus all files in all directories beneath the root directory. The backup command will not backup files in directories beneath the specified directory unless you use the /s switch. This command, since it specifies the root directory as the source and uses the /s switch, produces a backup of the entire hard drive C.
C:\>backup c:\lotus a:
Backs up files in the \lotus directory only. You can backup just a single directory with a command like this. Adding the /s switch to this command backs up the \lotus directory, plus all directories beneath the \lotus directory.
C:\>backup c:\ a: /s /m
Backs up only files that have changed since the last backup. Using the /m switch can save a great deal of time when making backups. It's not necessary to backup most program files, for example. They don't change, and if you lost them from the hard drive, you'd have the original diskettes to restore from. Also, the /m switch can lead to a rotating backup scheme that can save a great deal of time and effort when making backups.
Erases existing files
The backup command erases existing files on the diskettes used in the backup. For example, suppose on Friday you backup the entire hard disk to twenty diskettes. Then on Monday, you use the backup command with the /m switch, which will backup just Monday's changes, perhaps two diskettes worth. Since the backup command requires you to insert diskette number one, you insert the first one from Friday's backup, and then diskette number two. Of course, DOS erases the existing files from these diskettes. The important fact is that diskettes three through twenty are effectively erased too.
Restore Command
Restores files from backup diskettes
You must use the restore command to use files created by the backup command. That's because DOS adds special information to the backed up version of the file. You could use the copy command to copy the file from a backup disk to the hard drive, but the file probably won't be usable. Starting with version 3.3 of DOS, the backup command creates a single file on the backup diskette that may contain many small files. It's obvious that you must use the restore command to extract these files. Also, backup diskettes created with version 3.3 or greater of DOS are not compatible with earlier version of the restore command. This prevents you from using the backup and restore commands to transfer files from a computer using version 3.3 or greater to one running older versions.
C:\>restore a: c:\
Restores files from drive A to the root directory of drive C. Like the backup command, restore works with a single directory at a time unless you use a switch to include subdirectories.
C:\>restore a: c:\ /s
Restores files from drive A to the root directory of drive C, plus all directories within the root directory. The /s switch instructs the restore command to restore files to directories beneath the root directory. This command will restore all files from the backup diskettes.
C:\>restore a: c:\lotus
Restores files from drive A to the \lotus directory of drive C.
C:\>restore a: c:\lotus\budget.wk1
Restores the file budget.wk1 from the \lotus directory only.
C:\>restore a: c:\ /s /p
Restores files from drive A to the root directory of drive C, including all directories beneath the root directory, but asks whether to restore read-only and changed files. The /p switch to the restore command makes restore stop and ask whether to restore files that are marked as read-only, and whether to restore files that have changed since the last backup.
You might not want to restore files that have changed since the last backup, because if the file is still on the disk, and the file has changed since the last backup, then the version of the file that would be restored from the backup disk is older than the file already on the disk. If you didn't use the /p switch, the restore command would overwrite a file with an older version of the file--resulting in the loss of updates made to the file.
Backup Strategy
Since using the backup command can take a great deal of time, let's take a look at developing a strategy for more efficient backups. The strategy involves using the /m switch to the backup command to backup just those files that have changed, and using several sets of backup diskettes.
Format and prepare three sets of diskettes
Set A (A-1, A-2, A-3, etc..), Set B, Set C
If your disk is nearly full, you'll need a lot of diskettes for the first set, and somewhat fewer for the second and third sets. You don't need to label these now, as you can label them as the backup command requests them. You should, however, format them before the backup.
On Fridays
Perform a complete backup to set A with this command:
C:\>backup c:\ a: /s
Set A contains a backup copy of the entire fixed disk.
On Mondays
Perform an incremental backup to set B with this command:
C:\>backup c:\ a: /s /m
This command makes backup copies of only those files that changed since the last backup on Friday. Note the switches: we're using the /s switch to backup all directories on the disk, and we're using /m to make copies of only those files that changed since the last backup on Friday. This should take just one or two diskettes and about five minutes.
On Wednesdays
Perform an incremental backup to set C with this command:
C:\>backup c:\ a: /s /m
Again, this incremental backup, which backs up Tuesday's and Wednesday's data, shouldn't take very many diskettes or much time.
Repeat each week
Remember, the value of a backup depreciates very rapidly, so frequent backups are important.
If you follow the suggestion outlined earlier, where you create a \data directory with subdirectories beneath it, you may want to backup just the files in those directories. The commands for the backups become
C:\>backup c:\lotus a: /s
and
C:\>backup c:\lotus a: /s /m
Restore procedure
Restore the oldest set of diskettes first, then the next oldest, then the most recent.
If the worst happens, and you need to restore the entire disk, a group of files, or a single file, start the restore process by restoring from the oldest backup diskette set. Then restore the same files again, using the second-oldest set, and then finally restore them again from the most recent backup diskette set. For example, if you're following the above scheme, and you lose data on Thursday, restore from Friday's set, then Monday's, then Wednesday's. This will ensure that the restored files are the most recent version you've backed up. As you can imagine, it pays to adhere to the routine religiously, and to keep a log book of the day of the backup and the diskette set backed up to.
If the path to the oldest set of diskettes passes through a complete backup of the disk, you don't need to restore any older sets. For example, if you lose data on Tuesday, Wednesday's set is the oldest, but since Friday's set is a complete backup, just restore Friday's disks, then Monday's.
As a final note, the backup and restore commands work very well, except for one factor: the backup process is slow and requires a lot of patience. Many people purchase a tape drive for their computer. A tape drive holds a tape (tapes come in various formats and sizes) and under control of special software, copies data from the hard drive to the tape. Tapes have the advantage of large capacity (now usually over 120MB per tape, and some tapes hold over 1,000MB) and fast backup (usually at least several megabytes per minute). With a tape, you can reduce the time and effort it takes to perform a backup.
Some people, because of the tapes high capacity and speed, backup the entire hard drive. Others backup just their data files, using a process similar to those outlined above. Others perform incremental backups using different tapes, again similar to the procedure described above. With a tape drive, you don't use the DOS backup and restore commands; instead you use software that's usually supplied with the tape drive. That software will have options similar to DOS's backup and restore commands.
Exercise 4
The first exercises are paper exercises only.
1. Backup all files from the root directory of drive C to drive A.
2. Backup all files from drive C to drive A.
3. Backup only the new or modified files from drive C to drive A.
4. Your hard drive crashes and you have to replace it. Restore all your files.
5. You accidentally delete a file called C:\data\lotus\budget.wk1. Restore it.
6. Using the directory structure last created (with the directories \data\lotus and \data\wp), backup all your Lotus 1-2-3 and WordPerfect data files.
Perform the next exercises on your computer.
7. Using a blank diskette provided by your instructor, backup the data files in the \data directory of drive C.
8. If you know how to use Lotus 1-2-3 or WordPerfect, follow these steps: 1) Start either program. 2) Retrieve one of the existing data files, make a change to it, and save it again. 3) Create a new data file and save it.
9. Backup only the files in the \data directory that have changed since you last backed up. There should be two files.
Other DOS Commands
Internal vs. External Commands
The difference between internal and external DOS commands is that internal DOS commands are memory-resident and available for execution at any time the DOS prompt is displayed, while external DOS commands reside on disk, and that disk must be available to run the command.
DOS commands are computer programs just like any other, but they're a special class of program called systems programs, as opposed to applications programs like your spreadsheet, word processor, or database programs. Because some DOS commands are so vital, they're loaded into RAM memory at bootup time and stay there. Thus, you can run the internal commands--copy, dir, date, time, ver, path, prompt, erase, del, cd, md, rd, and a few others--at any time, no matter what disks are (or are not) in your machine.
External DOS commands--format, diskcopy, comp, diskcomp, tree, and chkdsk, to name a few--reside on a disk just like your word processing program. Thus, to run an external DOS command, like formatting a disk, the program file format.com or format.exe must be available for execution. Thus, you must either change to the disk and directory containing the program, or you must have the program accessible through the path command.
The Path Command
Most of the time, DOS treats each directory like a separate disk drive. Thus, if you want to run a program that's located in a directory, you generally need to use the cd command to change to that directory. Then, you can run the command. For example, if you have a fixed disk and all the external DOS commands (format.com, diskcopy.com, and so forth) located in a directory called c:\dos, and the current directory is not c:\dos, then an attempt to execute a command like format or diskcopy will fail, because DOS will not find the program file in the current directory. To allow DOS to look in other directories for commands, use the path command. Path allows you to specify alternative directories that may contain commands you want to execute. The format is
C:\>path [<directory>;...]
Suppose you want access to the root directory of the default disk. Simply type
C:\>path \
To let DOS find commands in a directory like c:\dos, the command is
C:\>path c:\dos
You can specify multiple paths by separating the individual directory paths with semicolons, as in
C:\>path c:\;c:\progs;b:\bill\progs\utility
DOS searches the directories in the order they appear on the path command line. Entering the path command with no parameters displays the current list of paths, and entering
C:\>path;
deletes all the paths. Each time you issue a path command, DOS disregards any existing paths and works with just the path most recently specified. Thus, to add a new directory to the search path, you must type the complete existing path command again, adding the new directory to the existing paths.
DOS does not check the validity of paths until DOS actually needs to search the erroneous path. This means that you can enter any path on the command line, even if the directories don't exist, and DOS will not issue an error message.
The path command finds only executable files. Thus, the only files path will find are those ending with the extensions .bat, .com, and .exe.
Check Disk (chkdsk) Command
C:\>chkdsk
This command shows the status of drive C.
Reports memory and disk usage
C:\>chkdsk /f
This version of the chkdsk command fixes disk errors. The disk's directory, which is what appears when you issue the dir command, also keeps track of the file sizes to the nearest byte. One of the tests chkdsk performs is to check that each file is assigned just enough clusters (clusters are groups of sectors on the disk) to hold the data indicated by the file size in the directory. If the two figures conflict, something's wrong with the disk, and chkdsk reports that clusters are lost.
Lost clusters usually appear on a disk when a program abandons a file it creates without performing all the steps necessary to establish a complete file. Here's how it works: a program decides to create a file. It first opens the file, which defines an entry in the directory, then fills the file with data, and finally closes the file. It's the closing part that's critical. If something happens that prevents the program from closing the file--power failure, rebooting, switching off the computer, a premature exit, removing a diskette, or just sloppy programming--clusters are left stranded on the disk, and chkdsk reports them as lost. That's why it's good to exit programs with their quit or exit commands and wait until the DOS prompt reappears before removing diskettes or switching off the computer. Many programs create temporary work files during their operation, and it's a good idea to give the program a chance to close them by exiting properly.
When chkdsk finds lost clusters, it reports their existence, but does nothing to correct the situation, even though it may ask you whether to save the clusters. That's where the /f switch to chkdsk comes in. When running chkdsk with the /f switch, as in C:\>chkdsk /f, chkdsk asks whether to throw away lost clusters, or to group them together and save them as a series of files.
Most of the time, you should not have chkdsk group the lost clusters into files. If you do, you'll get a series of files named file0001.chk, file0002.chk, and so forth which contain the data in the lost clusters. Look at them if you want, but realize that if you do see anything recognizable in them, you probably won't be able to use it, so you'll be erasing the files soon. That's because most programs--spreadsheet and database programs in particular--require their data files to be complete to be usable. For example, losing even one byte of a Lotus 1-2-3 worksheet file can render the whole file unusable. For word processing files, the .chk files may contain usable data.
Lost clusters, then, are usually harmless unless you notice you're losing transactions from your files. Unless they reappear frequently, you can usually ignore them--just use the chkdsk program with the /f switch and answer N when asked whether to save the lost clusters in a file. Otherwise, suspect the software you're using as the culprit.
Prompt Command
When using a disk with subdirectories, it's sometimes difficult to remember your current location in the directory structure. The standard DOS prompt reminds us of the default disk drive, but it doesn't remind us of the current directory. DOS does, however, have the prompt command, which allows us to fashion your own custom prompt. The prompt I designed looks like this:
IBM Personal Computer DOS Version 3.30
Mon 10-20-1987 14:33:57.25
Current directory C:\DATA\WP>
This prompt tells us the version of DOS we're using, the current date and time, and the current directory. This is the command to make your prompt look like the one above:
prompt $v $_$d $t $_Current directory $p$g
The way the prompt command works is through a set of special characters that direct the command what to display. The special characters are a dollar sign ($) followed by another character as in this table:
$t current time
$d current date
$p current directory of default drive
$v DOS version number
$n default disk drive
$g this character: >
$l this character: <
$b This character: |
$_ the underscore means start a new line
Whenever one of these special characters is included in the prompt command, it is replaced with the command's meaning upon display. You may mix these special characters with any regular text you desire. Give it a try--experimentation will show which prompt design works best for you. The most common prompt command is prompt $p$g, which displays the current drive and directory, followed by a greater than sign, as in
C:\DATA\WP>
If at any time you want to restore the prompt to its original form, simply type prompt without any parameters.
File Attributes
Each file, besides having a name and extension, also has attributes. Attributes are additional information that controls the state of the file. The two most important attributes are the read-only and archive attributes.
When the read-only attribute is set, you can read, but not delete or change the file. When this attribute is reset, you can delete or change the file as is the usual case.
The archive attribute tells whether the file has been copied with the backup or xcopy commands. DOS sets the archive attribute to indicate that a file is new or modified, and is in need of backup. The backup command and then xcopy command (when used with the /m switch) reset the archive attribute to indicate the file is currently backed up.
The attrib command lets you change the status of the read-only and archive attributes. The general format of the command looks like this:
C:\>attrib +r command.com
This command sets (the plus means to set) the read-only attribute for the command.com file. After this command, command.com is protected from accidental deletion. Repeating the same command, but changing the plus to a minus sign, resets the read-only attribute, and command.com is then subject to deletion or change.
To change the archive attribute of a file, use the same attrib command, but use +a to set the attribute, and -a to reset it.
With the attrib command, you can use wildcard file names. For example:
C:\>attrib +a *.wk1
This command sets the archive attribute for all the files with the .wk1 extension. The /s switch tells the attrib command to act on files in subdirectories of the current directory. For example:
C:\>attrib +a *.* /s
This command sets the archive attribute for all files on drive C, because the *.* file name indicates all files in the current directory (the root directory), and the /s switch indicates all files in the subdirectories.
C:\>attrib *.*
This command, the attrib command entered with just a filename, displays the attributes for the indicated files (all files in this example). It does not change any attributes.
Diskcopy Command
Duplicates diskettes
The diskcopy command produces an exact duplicate of the source diskette. That's a very important point. It means that if there were files on the target diskette that don't exist on the source diskette, those particular files on the target diskette won't be there anymore after the diskcopy.
Hard drive computer procedure
C:\>diskcopy a: b:
Swap source and target diskettes as requested.
Also, what if your computer has just a single floppy drive, as is the case with most hard drive computers? The single floppy functions as both drive A and B. DOS first asks for the source diskette, reads the source diskette into RAM memory, then DOS asks for the target diskette and writes from RAM to the target. If you have enough RAM, you'll exchange the diskettes just once, but for high-density diskettes or low-memory computers, DOS may ask for the source and target diskettes again.
Erases target before copying
As mentioned earlier, diskcopy produces an exact duplicate of the target diskette. You should think of diskcopy as deleting all the files on the target before it copies the source files. What would happen if the source diskette was totally blank, but the target diskette contained many files? After diskcopy, the target is a duplicate of the source, so it is blank, too.
Can accept unformatted target diskette
Diskcopy is the only command besides format that will work with an unformatted diskette. If diskcopy senses the target is not formatted, it will format as it copies.
Works with diskettes only
Diskcopy won't work to copy files either to or from a hard disk drive.
Xcopy
The xcopy command is a special version of the copy command that has additional features that the regular copy or diskcopy commands don't have. The two most important feature of the xcopy command is the ability to copy a directory and its subdirectories, and the ability to work with the archive file attribute.
The first benefit of the xcopy command, the ability to copy files and directories, works like this. Suppose that on drive C, we have the \data\lotus and \data\wp directories. You'd like to copy all the files in these directories to drive A. This command will perform this act:
C:\>xcopy \data a:\ /s
The source of the copy, the directory \data, copies files from that directory to the root directory of drive A. The /s switch means to include directories. After this command, there will be two directories on drive A: \wp and \lotus, each containing files from drive C.
A similar, but very different xcopy command is this:
C:\>xcopy \data a:\data /s
In this case, xcopy will create a directory on drive A called \data, with \data\lotus and \data\wp directories within it and the proper files in those directories. The difference between this command and the previous is in using a directory name as a target. Xcopy will ask whether the a:\data target represents a file or directory name on the target drive, drive A. In this case, answer D for directory. If you answer F for file, the xcopy command creates a file in the root directory of drive A called data, and copies the source files to that file.
The /e switch, used along with the /s switch of the xcopy command, instructs this command to create all directories on the target drive, even if the source directory is empty. Without using /e, xcopy will not create empty directories.
The second benefit of the xcopy command is its ability to use file attributes. The /a switch copies only those files for which the archive attribute is set. (Remember that the archive attribute is set when the file is new, or when it has been modified since it was copied with the backup command.) Therefore, using the /a switch copies only those files that are not currently backed up.
Using the /m switch works like the /a switch, in that only the files with their archive attributes set are copied. With this switch, however, the xcopy command resets or turns off the archive attribute after the file is copied. The /m switch for this command, then, works just like it does for the backup command.
Mode Command
The mode command is a single command that accomplishes several functions, dealing with printers, displays, communications ports, and perhaps other features unique to your computer.
Initializes serial ports
C:\>mode COMn: buadrate,parity,databits,stopbits,p
C:\>mode COM1: 9600,n,8,1,p
This use of the mode command is perhaps the most important. It initializes the serial ports on your computer for a certain baud rate, parity, data length, and number of stop bits. The primary use of the mode command is when you have a serial (as opposed to parallel) printer attached to your computer, and your software doesn't support direct connection to a serial printer. Serial (also called asynchronous) and parallel refer to two methods of connecting peripheral devices to a computer. Most printers designed for use on the IBM PC are parallel printers, but a few are serial.
Redirects printer output
C:\>mode LPTx: = COMy:
C:\>mode LPT1: = COM1:
Much PC software is setup to send printed output to the parallel printer port called LPT1. If you have a parallel printer, it's almost certainly attached to this port and you don't need to redirect the output. If you have a serial printer, however, it's connected to either the COM1 or COM2 port. This use of the mode command intercepts output sent to a parallel port and sends it to a serial port.
The ability of the mode command to redirect printer output from a parallel port to a serial port is necessary because some software can send data only to the LPT1 parallel port. Much new software, however, can handle this task directly. For example, when installing a printer in WordPerfect, you specify the port the printer is connected to, along with the communications parameters (baud rate, parity, databits, stop bits). This capability of WordPerfect makes the mode command unnecessary, and is preferable to the other method, designating to WordPerfect that the printer is attached to LPT1 and using mode to send the output to the COM port. Microsoft Word, on the other hand, can direct output to COM1 or COM2 but doesn't handle the communications parameters itself, so it's still necessary to use a command like mode COM1: 9600, n, 8, 1, p to set these parameters. Some software still insists on sending output only to LPT1, so it's necessary to use both of these commands. It's necessary to use both commands for the Print Screen key to work with a serial printer, or for redirection of output to the printer (as in dir >prn) to work with serial printers.
Display parameters
C:\>mode BW80
The primary use of the mode command in conjunction with the computer's display is the case of a monochrome (single-color) display used with a color graphics display adapter card. In this case, software may send color output to the display, but since the display is monochrome, it can't interpret the colors correctly. Data may not be visible, or it may be unclear. This command disables color, so the screen will be clearer.
Settings gone after reset
You'll need to enter this command each time you boot your computer--the mode settings are not permanent. It's good to place these commands in a batch file.
Configuring Your Computer
Config.sys file
Config.sys is a special file that DOS uses to configure your system to suit your specific needs. DOS reads config.sys when you turn on your computer or reboot it. There are several things that config.sys can do, but three tasks are most important for everyday use: establishing the maximum number of files that can be open at any time, setting up disk buffers, and installing device drivers.
Files=nn
Many programs open or access multiple disk files simultaneously. For example, when using dBase III, you might have three or four database files open, several index files, temporary sort files, format files, and program files. But to open a file, DOS must reserve a small amount of memory to hold housekeeping information about the file. Without the files=nn statement in your config.sys file, DOS allocates space to open eight files--not enough for many programs. For most people, a value of 20 is sufficient, so the statement should look like this: files=20. If you need more files, your software's installation guide should specify the number needed.
Buffers=nn
The buffers=nn statement, simple as it is and so easy to create, can increase the performance of your system dramatically. The buffers statement reserves part of RAM memory for use as a disk buffer. It works like this: accessing the disk drive is slow, but accessing RAM is fast. Suppose that instead of accessing the disk several times (each access takes a lot of time) to fetch small amounts of data, DOS accesses the disk once and loads a large amount of data into the disk buffers located in RAM. Then, whenever the computer needs information from the disk, it first searches through the RAM buffer to locate the data. If it finds what it needs in the buffer--and depending on the nature of the data, there's a poor to good chance it will--the access will proceed much faster than if the computer went straight to the disk. If the computer doesn't find what it needs in the buffer, not much time is lost, as the search through the buffer is very rapid.
With too few buffers, you won't realize the benefits buffers can provide, and too many buffers can actually slow down performance. Each buffer occupies 512 bytes (one-half a kilobyte) of RAM, you clearly can't have an infinite number of buffers. How many should you use? For most people, a value of 24 is about the best, and it uses just 12 KB RAM memory, something nearly everyone can afford. In your config.sys file, then, you'd want the statement buffers=24.
A common feature of many computers is use of a more sophisticated disk cache program, such as the smartdrv.sys program that's supplied with Microsoft Windows. With use of a program like this, you may or may not want to use the buffers statement. Consult the instructions for the disk cache program for advice.
Device Drivers
Installable device drivers let developers attach devices to DOS in a controlled, standard manner, allowing DOS to work with many different accessory devices, ranging from hard disk drives, tape backup systems, mouses, special screen drivers, and so forth. For example, the Microsoft Mouse uses a device driver found in a disk file called mouse.sys, so in your config.sys file you'd have the statement device=mouse.sys. This assumes that the mouse.sys file is in the root directory of drive C. If it was located in the c:\dos directory, for example, the correct statement is device=c:\dos\mouse.sys. Your software's installation guide should lead you through the steps of adding the device driver statement to your config.sys file. It's not uncommon for many program's installation routine to add any necessary statements automatically.
Shell
The shell statement in the config.sys file is primarily used to allocate memory to DOS's environment. This environment is where DOS stores variables like the search path specified in the path command, information entered with the set command, and other miscellaneous information. Occasionally, the environment may become full, and you need additional space to store additional environmental information. This statement:
shell=c:\command.com /e:256 /p
specifies an environment size of 256 bytes. The number you specify can be from 160 through 32768 bytes. The /p switch is necessary to make command.com the permanent command processor.
It is unusual to see a configuration that needs more than about 512 bytes for the environment space. The default amount of environment space varies with the different versions of DOS.
Read at boot time only
DOS looks a config.sys just once--at boot-up time, when it loads all the device drivers and configures the buffers and file housekeeping space. If you make changes to config.sys, you must reboot the computer with the control-alternate-delete key sequence; otherwise, DOS is unaware of your modifications.
The Tree Command
Displays directory structure
One handy command that lets you see the directory structure of your disk is the tree command.
C:\>tree
This command displays a list of all the directories on the disk, along with each directory's subdirectories..
C:\>tree /f
This command displays files within each directory.
You can add the /a switch to cause the tree command output to be text characters rather than graphic characters. This may work better with some printers or import better into some word processing programs.
Label Command
Each disk has a volume label, a name that appears at the top of the dir and chkdsk command's output. That's about all the volume label does, although some programs like Microsoft Windows use it for minor purposes.
C:\>format a: /v
This command formats the disk in drive A, and prompts for volume label. DOS will prompt you to enter up to 11 characters to use for the label.
C:\>label
Changes volume label for drive C.
C:\>label a:
Changes volume label for drive A.
The vol command displays the volume name of the current disk.
Redirecting Output
Redirecting command output provides a means of printing the output of a command like dir or tree. Also, you can incorporate the command output into other programs.
C:\>tree /f > prn
This command sends the output of the tree /f command to the printer. The greater than sign (>) is the redirector, which means that it captures the output of a command and sends it to prn, which is the name DOS uses for the printer.
C:\>tree /f > tree.txt
Sends the output of the tree /f command to the disk file tree.txt. Here, we redirect the output to a disk file called tree.txt. You might do this because when redirecting command output to the printer, there are no margins, and the printer will print over the perforation separating one page from another. Or if you're using hand-fed sheets, the printer won't wait for you to place the next sheet in the printer. But once the output of a command is in a disk file, you can load it into your word processing program and print it from there, using margins, deleting unneeded material, adding additional titles, or whatever you want.
The files that redirection creates are called ASCII (American Standard Code for Information Interchange) files. ASCII is a generic file format that most programs can understand. Most word processing (and other programs, too) have a special command for loading an ASCII file, so use that procedure when working with redirected files.
C:\>dir > tree.txt
Sends the output of the dir command to the disk file tree.txt. If you issue this command after the tree /f > tree.txt command, DOS first overwrites the existing file (which contains the tree command output) and replaces it with the dir command output.
C:\>dir >> tree.txt
Appends the output of the dir command to the disk file tree.txt. When using two greater than signs as the redirector symbol, DOS adds the output of the command to the end of the existing file. In this way, you can group several commands' output into a single file for later editing and printing.
Exercise 5
1. Use the chkdsk command to check the status of files on drive C.
2. If chkdsk reports a problem, did you elect to repair it? What option must you use to get chkdsk to repair errors?
3. Change the disk label of your data diskette in drive A to "BOB"
4. Print a directory listing of the root directory of drive C.
5. Print the directory structure of drive C.
6. Capture the directory structure of drive C and all the files on drive C to a disk file called "tree.txt" located on drive A. View this file with the type command.
7. Make an exact duplicate of your data diskette onto a disk that your instructor supplies.
8. Suppose your computer has these software programs: WordPerfect installed in C:\wp, dBase IV installed in d:\dbase4, DOS external programs installed in c:\dos, and several batch files installed in c:\dos\batch. Write a path statement to accommodate running these programs from any directory or disk.
9. Your laser printer is serial and requires settings of 9600 baud, eight data bits, one stop bit, and no parity. Write mode statements to accommodate this printer.
10. Your laser printer is parallel. Write mode statements to accommodate this printer.
Batch Files
Batch files are one of the most useful and time-saving features of DOS. With batch files, you can "program" many common DOS operations.
A batch file is a file that contains DOS commands. The file has a name with the extension .bat, such as startup.bat. When you type the name of the batch file at the DOS prompt, like
C:\>startup
DOS executes the commands in the batch file, one by one, just as though you were typing them at the DOS prompt yourself.
Let's take a common example. If you have a program installed in a subdirectory of a hard disk drive, you often want to change directories to the program's directory before you run the program. After running the program, it's common to change back to the root directory. If you type the commands yourself, the sequence of commands (using Lotus 1-2-3 as the example program, stored in a directory called \lotus on the hard drive C) would look like this:
C:\>cd \lotus
C:\LOTUS>lotus
C:\LOTUS>cd \
If you placed these commands in a batch file called l.bat, all you'd need to do to run Lotus 1-2-3 is to issue this command:
C:\>l
The batch file first uses the cd command to log into the \lotus directory, then issues the command lotus, which loads the Lotus 1-2-3 software. At this time, the batch file steps into the background and Lotus takes over. When you issue the command to quit Lotus 1-2-3, DOS takes over and runs the batch file starting at the next line, which issues the cd \ command to log back to the root directory. Since that's the last command in the batch file, DOS displays the prompt (C:\>) and is finished with this batch file.
Another example: If you have a serial printer, you often have to issue the mode command to initialize the serial port and redirect output from the LPT1 port to the COM1 or COM2 port. These two commands (example for the Hewlett-Packard LaserJet printer):
C:\>mode com1: 9600,n,8,1,p
C:\>mode lpt1: = com1:
could go in a batch file called lj.bat. To setup the computer for this printer, then, all you'd type is
C:\>lj
Creating Batch Files
To use batch files, you must have a way of creating the file. Batch files are ASCII files (sometimes called DOS text files) and can't contain any of the formatting that word processing programs add to their document files.
One way that everyone has to create batch files is with the Edit or Edlin text editors that are supplied with DOS. Edlin has been around since the beginning, and many people find edlin cumbersome to use. Edit is a new program for DOS 5.0, and is more like the word processing programs that many people already know how to use.
Another way to create batch files is to copy lines of text directly from the keyboard to a file. This method works like this: First, type the command to copy from the keyboard to a disk file. If you want to create a batch file called lj.bat, this is the command to use:
C:\>copy con: lj.bat
Con: is the DOS device name for the keyboard.
Now, type the lines to include in the batch file, pressing Enter at the end of each line. Be careful, though, because you can't correct a line after you press Enter to end it. Before pressing Enter you can use the backspace key to make corrections. After entering all the lines, press F6 (function key 6) twice. This key enters the end-of-file character control-Z, which displays on the screen as ^Z. Then press Enter once again, and the computer creates the batch file.
This method, subject to the editing limitations, works well. You won't be able to correct the batch file later if you notice an error or want to make an addition to it--but you can issue the copy command again and reenter the entire batch file. (Of course, you can edit the batch file with edit or edlin.)
Many word processing programs can store a document as an ASCII file by using a special save or conversion command. If your word processor (or other software) can save text as ASCII files, use it to create batch files. Here's a list of common software and the commands to save and retrieve ASCII files:
Microsoft Word - To save as ASCII, use the Transfer Save command as regular, type the file name (be sure to include the .bat file extension), and select "No" in the "Formatted" command field. To retrieve an ASCII file, use the Transfer Load command. Type the name of the batch file and press Enter (the file name will not appear in a list of documents because its extension is .bat instead of .doc).
Sidekick - The Sidekick editor works directly with ASCII files. No special save or retrieve commands are necessary.
WordPerfect - To save as ASCII, press the Text In/Out key (control-F5). Select "DOS Text," select "Save," and type the batch file name (be sure to include the .bat file extension). To retrieve as ASCII, use menu option 1 (Retrieve) from the List Files menu, or from the Text In/Out menu (control-F5), select "DOS Text" and then "Retrieve." If you have WordPerfect Office, the Editor works with ASCII files directly without special save or retrieve commands.
WordStar - Create the batch file by using the "N" (Non-document) command from the Opening Menu. Save as regular, with control-KD. When editing the batch file, use "N" from the Opening Menu again. For WordStar 2000, use the "Unform" style sheet.
Microsoft Windows - The Notepad application (found in the Accessories window) works with ASCII text files directly. Just open and close files as usual.
Autoexec.bat
When the computer loads DOS, either because you turned the computer on or used Control-Alternate-Delete to force a restart, DOS looks in the root directory of the startup disk for a batch file called autoexec.bat. If it finds it, it runs the batch file. This mechanism provides for automatically executing commands each time you start the computer.
Common things to place in autoexec.bat are mode commands for serial port setup (like the example for the Hewlett-Packard laser printer example above), commands to load memory-resident accessory programs, commands to set the date and time, the path command, the prompt $p$g command for a more informative prompt, menu programs, and anything else you'd like to add.
If DOS finds an autoexec.bat file, DOS doesn't execute the date and time commands as it would otherwise. If you don't have an automatic clock and calendar in your computer, you'll want to place the date and time commands in your autoexec.bat to make sure you get a chance to set the date and time properly. In the autoexec.bat file, the commands look like this:
date
time
Exercise 6
1. WordPerfect is installed in c:\wp50. Write a batch file that changes to that directory, starts WordPerfect (the command is wp), and returns to the root directory of drive C when finished. Make sure the batch file will work no matter what the current drive and directory are. Call the batch file w.
Commands for Batch Files
Batch files may contain special commands that make them work better. Here are some special commands you may want to use.
Echo
This command performs two functions: it turns off the display of commands during execution of a batch file, and it displays messages.
Turning off the display is merely cosmetic. All it means is that the commands in the batch file won't show on the display. To turn the display of batch file commands off, use the command
echo off
and to turn the display of commands back on, use
echo on
Initially, echo is on. To display a message, use a command like
echo Type lotus to run Lotus 1-2-3
To suppress the display of a single command, precede the command with the @ character. For example, to suppress a change directory command, use a line like this:
@cd \data\lotus
Even with echo off, the results of commands will show on the display. For example, if the batch file issues a copy command, DOS will show the names of the files as it copies them. To suppress the display of the results of commands, redirect the output of the command to the null device nul as follows:
copy *.* a: >nul
Now the copy command will not produce visible output. It's best to include an informative message at times like this so that the user doesn't become impatient, as in:
echo Please wait while copying files
copy *.* a: >nul
Remarks (Rem)
The rem command lets you add statements to the batch file that don't execute. Instead, they provide a comment or reminder. A remark statement looks like this:
rem After changing to the \lotus directory, start the Lotus software
When running the batch file, DOS skips over this statement. If echo is on, however, you'll see the comment on the display.
Pause
The pause command displays an optional message on the screen, and then the message "Strike a key when ready..." This command is useful when the batch file requires a change of diskettes, inserting a certain diskette, turning the printer on, and so forth.
For example, old versions of Lotus 1-2-3 are copy-protected and require that the original program diskette be in drive A when starting the program, even when running 1-2-3 from a hard disk drive. (This is not entirely true, but it will serve for illustration.) Use these lines in a batch file called lotus.bat:
pause Insert the Lotus 1-2-3 System Diskette in Drive A
cd \lotus
lotus
cd \
When this batch file runs, it will display the message
Insert the Lotus 1-2-3 System Diskette in Drive A
Strike a key when ready...
After the user places the system disk in drive A and presses any key, DOS continues with the rest of the batch file.
Cls (Clear Screen)
At any time, you can type cls at the DOS prompt and the computer clears the screen, displaying the prompt on the top line of the display. This is often useful in batch files as a cosmetic aid to avoid leaving displays from the last program on the screen. WordPerfect, for example, doesn't clear the screen upon exiting the program. Using cls in a batch file will clear the screen automatically.
Call
The call command lets you run a second batch file from within a batch file, returning to the original batch file when the called batch file finishes. This special call command is necessary because without it, the second batch file will not return to the first. For example, consider these two batch files:
1.bat:
echo this is in 1.bat
2
echo this is back in 1.bat
2.bat:
echo this is in 2.bat
Running 1.bat produces output like this:
this is in 1.bat
this is in 2.bat
You can see that the last line of 1.bat is never executed, as after 2.bat terminates, control never passes back to 1.bat. If you modify 1.bat to look like this:
echo this is in 1.bat
call 2
echo this is back in 1.bat
Running 1.bat now produces this output:
this is in 1.bat
this is in 2.bat
this is back in 1.bat
You can see that after 2.bat finishes, control returns to 1.bat, and the next line in 1.bat executes.
Replaceable Command Line Parameters
This batch file concept lets you communicate information to the batch file through the DOS command line. Here's a common example: When using WordPerfect, if you issue the wp command like this:
wp /m=startup
WordPerfect will execute the macro called startup automatically. The problem is that we have WordPerfect installed in a directory called \wp, and our batch file, called wp.bat, looks like this:
cd \wp
wp
cd \
cls
Typing wp /m=startup doesn't do much good here, as the batch file simply issues the command wp once it changes to the \wp directory. We could rewrite the batch file as:
cd \wp
wp /m=startup
cd \
cls
But then the batch file would have WordPerfect run the same macro, startup, every time it runs. We want a way to communicate a different macro to the batch file each time we run WordPerfect. Here's a batch file that will do this:
cd \wp
wp /m=%1
cd \
cls
The key to this batch file is using %1 for the name of the batch file that WordPerfect should run. This is called a replaceable parameter.
There are ten replaceable parameters available, %1 through %9. %1 represents the first word typed on the DOS command line after the name of the batch file that DOS should run, %2 the second, %3 the third, and so forth. %0 (zero, not Oh) is the name of the batch file itself. For example, if you typed:
C:\>wp startup
Startup is the first parameter to the batch file, and any time you use %1 in the batch file, it's replaced with startup. Therefore, if you type wp startup at the C:\> prompt, the batch file that actually runs is
cd \wp
wp /m=startup
cd \
cls
In the line that reads wp /m=%1, the %1 is replaced with startup, producing the line wp /m=startup.
Another example: When using Microsoft Word, you might want to transmit two parameters to the batch file, a command switch such as /c to make Word operate in character mode, and perhaps a document name to edit. We need two replaceable parameters in a batch file like this (word is the command to start Microsoft Word, and it's stored in a directory called \word):
cd \word
word %1 %2
cd \
cls
If you entered
C:\>word budget /c
The line word %1 %2 becomes
C:\>word budget /c.
Exercise 7
1. Modify the existing w batch file so that it passes parameters to WordPerfect. There could be up to five parameters.
2. Modify the existing w batch file so that it hides its action from the user. Have it clear the screen when finished.
3. Create batch files called mon, wed, and fri to implement the backup strategy discussed earlier.
The Goto Command and Labels
The goto command lets you control the flow of execution in a batch file, similarly to goto statements in programming language. Goto works by causing DOS to branch to a label and continue executing batch file statements at the label. The goto command looks like this
goto <label>
Fill in <label> with the name of the label to branch to.
Labels are words preceded by a colon that mark a location in the batch file that you'd like to branch to at some time. A typical label looks like this:
:error
This label probably marks the start of an error routine in the batch file. The label statement does nothing itself, but merely marks the place to branch to with the goto command. Execution starts with the next command after the label. If the batch file is executing commands and comes across the label, the label has no effect.
Goto and labels are most useful when combined with the if command.
The If command
The if command lets you make decisions during execution of a batch file and perform different actions based upon some condition. The if command looks like this:
if <condition> <command>
Fill in <condition> and <command> with what you need to make the if command work for you.
Conditions may be of three types:
Testing the value of a replaceable parameter. For example:
if %1 == a: goto adrive
if %1 == c: goto cdrive
These two if commands test the value of the replaceable parameter %1. If it's equal to a:, the first if command causes a branch to the label adrive. If %1 isn't equal to a:, the if command does nothing, and the batch file executes the second if command, which performs a similar function.
Note the use of two equal signs to make the comparison. This is necessary as defined by the makers of DOS; one equal sign won't work. Also, what if nothing was typed after the name of the batch file? In this case, the replaceable parameters have no values at all. The line if %1 == a: goto adrive becomes if == a: goto adrive. This is not the proper syntax of the if command, so that command generates an error. Use this command instead:
if .%1. == .a:. goto adrive
If %1 contains nothing, the if command becomes if .. == .a:. goto a drive and the test fails, as it should. But if %1 is a:, the command becomes if .a:. == .a:. goto adrive, which passes as it also should.
Finally, the tests the if command performs are sensitive to case. Testing A: against a: fails, as capital letters are not the same as lower case.
A second use of the if command is to see whether a file exists on a disk. For example:
if exist test.doc erase test.doc
This command tests to see if the file test.doc exists. If it does, DOS executes the command erase test.doc. Otherwise, this command does nothing.
With all forms of the if command, you can use the word not to reverse the meaning of the comparison. For example:
if not exist test.doc copy a:test.doc
This command test to see if the file test.doc exists on the default drive. If it does not, it's copied from the A drive. Otherwise, nothing happens.
The third form of the if command is to test the errorlevel of a program. The errorlevel is a numeric variable that a program may set when it finishes. Not many programs or commands do set the errorlevel variable, but for those that do, you can test it with a command like this:
if errorlevel 2 goto help
If the errorlevel variable has a value equal to or greater than 2 (in this example), the test passes, and DOS executes the command goto help. This is the only type of test you can make of errorlevel; testing to see if it's greater than or equal to a value.
Exercise 8
1. Create a batch file called format that prevents the hard drive C from being formatted. Have the batch file display a message if the user tries to format drive C. If the target of the format is any other drive, go ahead and perform the format. Make sure that the DOS format program receives any parameters passed to it.
2. Discuss how the location of the batch file you just created and the path statement will interact to determine whether this command will work.
Using Edit
Edit is a new program for DOS 5.0 that lets you edit plain text (ASCII) files. To start the edit program, select it from the shell, or you can type edit and press the Enter key at a C:\> prompt, or you can use a command like this:
C:\>edit autoexec.bat
In this example, edit starts and loads the file autoexec.bat automatically.
Edit works with menus just like shell does. Basically, to select a menu command, press and release Alt or F10. Then, use the arrow keys to highlight the command you want and press the Enter key. Or, touch the highlighted letter in the command you want. With a mouse you can click on the command you want.
Edit's dialog boxes work much the same way. Use Tab or Shift+Tab to move from area to area. Use the arrow keys to move in a list box.
Editing Text
To add text, move the cursor to where you want the new text and type. Edit works normally in insert mode, so what you type is inserted at the cursor position.
To delete text, move the cursor to the character to delete and press the Delete key. You can also select a region of text before pressing the Delete key.
To move or copy text, start by selecting the text to move or copy. You can select text by first moving the cursor to the first character to select. Then, hold down the Shift key while you move the cursor. Once you've selected the text, you can then issue a menu command.
To move text, select the Cut command from the Edit menu. To copy text, select the Copy command from the Edit menu. Then, move the cursor to where you want the moved or copied text to appear, and select the Paste command from the Edit menu.
Opening a File
To open an existing file, issue the Open command from the File menu. You'll see a dialog box like this:
+----------------------------- Open ------------------------------+
¦ +--------------------------------------------------+ ¦
¦ File Name: ¦*.BAT ¦ ¦
¦ +--------------------------------------------------+ ¦
¦ A:\ ¦
¦ Files Dirs/Drives ¦
¦ +-------------------------------------------+ +--------------+ ¦
¦ ¦ AUTOEXEC.BAT ¦ ¦ DBASE ¦
¦ ¦ LOTUS.BAT ¦ ¦ LOTUS ¦
¦ ¦ ¦ ¦ WORD _ ¦
¦ ¦ ¦ ¦ [-A-] _ ¦
¦ ¦ ¦ ¦ [-B-] _ ¦
¦ ¦ ¦ ¦ [-C-] _ ¦
¦ ¦ ¦ ¦ [-F-] _ ¦
¦ ¦ ¦ ¦ [-G-] ¦
¦ + ________________________________________ + +--------------+ ¦
¦ ¦
+-----------------------------------------------------------------¦
¦ < OK > < Cancel > < Help > ¦
In the File Name text box, you can type the name of the file to open. Or, you can type something like *.bat and press the Enter key, and you'll see a list of all the batch files found in the current directory.
To select a file in the Files list, press Tab until the cursor moves to the list. Then, use the up or down arrow keys to highlight the file, and press the Enter key. With a mouse, click on the file name and click on OK.
To use a different drive or directory, press Tab until the cursor is in the Dirs/Drives list box. Use up or down arrow to highlight the drive or directory name and press the Enter key. The entry .. means the current directory's parent. For example, if the current directory is \data\lotus, selecting .. makes the current directory be \lotus. Selecting .. again makes the current directory \.
File Menu Commands
New creates a new file.
Open presents a dialog box where you can open or retrieve an existing file.
Save saves the file using its existing name, or if the file has never been saved, presents a dialog box where you can enter a name.
Save As presents a dialog box where you can enter a name for this file. This command lets you leave the original of a file intact and create a new file containing the current edit contents.
Print prints the file to the printer.
Exit leaves edit and returns to the command prompt or shell.
Edit Menu Commands
Cut (shortcut Shift+Del) cuts the selected text to the clipboard for later use.
Copy (shortcut Ctrl+Ins) copies the selected text to the clipboard for later use.
Paste (shortcut Shift+Ins) inserts the text from the clipboard at the current cursor position.
Clear (shortcut Del) deletes the selected text.
Search Menu Commands
Find presents a dialog box where you can fill in text to search for.
Repeat Last Find finds the next occurrence of what you looked for using the Find command.
Change presents a dialog box where you can find something, and then change it to something else.
Using Edlin
Edlin is a simple line editor supplied with DOS. Edlin doesn't have many of the features of other editors and word processors, such as the ability to move the cursor around the screen. But edlin does have the ability to create and edit batch files, and is well suited to this task.
Creating a File
To create a file in edlin, follow these steps:
1. Issue the edlin command along with the name of the file that you want to create. To create a file called lotus.bat, issue this command:
C:\>edlin lotus.bat
2. From the edlin prompt (the asterisk), issue the insert lines command by typing the letter i and pressing Enter.
3. Type the lines to go in the file. End each line with the Enter key. Use the backspace key to back up and make corrections. Remember that the asterisk that appears is the edlin prompt, not part of the text in the file.
4. To complete the entry of lines, press Control-Break or Control-C.
5. Issue the end edit command to complete the edlin session and save the file to disk by typing the letter e and pressing the Enter key.
Editing an Existing File
To edit an existing file, follow these steps:
1. Issue the edlin command followed by the file name that you want to edit. To edit an existing file called disk.bat, enter this line:
C:\>edlin disk.bat
2. Make changes to the file, as described later on.
3. Issue the end edit command to complete the edlin session and save the file back to disk. Do this by typing the letter e and pressing the Enter key.
4. To end the edlin session without saving the changed file, issue the quit edit command by typing the letter q and pressing the Enter key. Edlin asks for confirmation before quitting without saving.
When you update an existing file, edlin renames the original file on the disk with the same name, but the extension bak. The file disk.bat, for example, becomes disk.bak. This serves as a fallback mechanism should you mess up the original file during editing.
Displaying Lines
To display lines when editing a file, issue the list lines command by typing l and pressing the Enter key. Edlin displays up to 24 lines of the file. Each line has a line number for referring to that line during editing commands. Edlin also maintains the current line, identified by the asterisk before the line number.
The page command (the letter p followed by the Enter key) displays lines like the list lines command, but moves the current line marker. The list lines command doesn't move the current line.
Editing Lines
To edit an existing line, type its line number at the edlin prompt and press the Enter key. You can then type a new line and press the Enter key. The new line that you type replaces the existing line.
To add text to a line, follow these steps:
1. Use the right arrow key to "bring back" characters from the existing line until you come to the point at which you want to insert text.
2. Press the Insert key.
3. Type the characters that you want to insert.
4. Press the right arrow key again to "bring back" the rest of the characters from the last part of the line.
5. Press Enter to complete the edit of this line.
For example, suppose that a line currently looks like this:
copy disk. a:
You need to make the line look like this:
copy disk.bat a:
1. Type the line's line number and press Enter to start the editing.
2. Press the right arrow key until the period shows.
3. Press the Insert key and type bat.
4. Press right arrow again until the rest of the line displays.
5. Press Enter to complete the edit.
To delete characters from a line, follow these steps:
1. Type the line's line number and press Enter to start the editing.
2. Press the right arrow key until the character before the character you want to delete appears.
3. Press the Delete key once for each character you want to delete.
4. Press right arrow again until the rest of the line displays.
5. Press Enter to complete the edit.
Deleting Lines
To delete lines, use the delete lines command. Typing d and pressing Enter deletes the current line. 5d deletes line five. 3,5d deletes lines three through five.
Inserting New Lines
To insert new lines, use the insert lines command. Typing i and pressing Enter inserts lines above the current line. Typing 5i and pressing Enter starts entering lines before line five. Press Control-Break or Control-C to complete the new line entry.
Answers to Exercise 1
Complete these paper exercises by writing down the answers. Your instructor will discuss the answers after everyone completes the questions.
For these questions, assume these facts unless otherwise stated: A floppy diskette in drive A contains Lotus 1-2-3 worksheet files (with the extension .wk1), WordPerfect files (extension .wp), and dBase database files (extension .dbf). The computer has a hard drive C, and the prompt is C:\>.
1. List all files on drive C, screen-by-screen.
C:\>dir /p
2. List all files on drive A in a wide format.
C:\>dir a: /w
3. List all the Lotus 1-2-3 worksheet files on drive A, page-by-page.
C:\>dir a:*.wk1 /p
4. Copy the Lotus 1-2-3 worksheet BUDGET1 from drive A to drive C.
C:\>copy a:budget1.wk1 c:
or
C:\>copy a:budget1.wk1
5. Copy the Lotus 1-2-3 worksheet BUDGET1 from drive A to drive C, renaming it 1988B in the process.
C:\>copy a:budget1.wk1 c:1988b.wk1
or
C:\>copy a:budget1.wk1 1988b.wk1
6. Copy all WordPerfect documents from drive A to drive C.
C:\>copy a:*.wp c:
or
C:\>copy a:*.wp
7. Correspondence produced for John Doe has the extension .jd. Copy his files from drive A to drive C.
C:\>copy a:*.jd c:
or
C:\>copy a:*.jd
8. There is a series of Lotus 1-2-3 worksheet files on drive A called BUDGET followed by a single numeric digit (BUDGET1, BUDGET2, etc..) Copy all of them from drive A to drive C.
C:\>copy a:budget?.wk1 c:
or
C:\>copy a:budget?.wk1
9. Copy all files from drive A to drive C.
C:\>copy a:*.* c:
or
C:\>copy a:*.*
10. Rename the Lotus 1-2-3 worksheet file on drive C from 1988B to BUDGET.
C:\>rename 1988b.wk1 budget.wk1
11. Delete the Lotus 1-2-3 worksheet file BUDGET on Drive C.
C:\>del budget.wk1
12. Delete all the dBase database files from drive A.
C:\>del a:*.dbf
13. Delete all files from drive A.
C:\>del a:*.*
14. Whoops, the wrong disk was in drive A for the previous question. What would you do?
C:\>undelete a:*.*
Don't copy additional files to the disk until you attempt an undelete.
Answers to Exercise 2
Create this directory structure on the hard drive C:
|----- home
|
|----- ss -------|----- work
| |
| |----- school
\ --------|----- db
|
|
|----- wp
Issue these commands:
C:\>md \ss
C:\>md \ss\home
C:\>md \ss\work
C:\>md \ss\school
C:\>md \db
C:\>md \wp
Answers to Exercise 3
Perform these exercises on your computer. When deleting files, please make absolutely sure that you're in the correct directory or have specified the correct path to the files you're deleting. Please ask your instructor to check any commands that you may not be sure of. There may be more than one method for completing many of the actions you are to perform. See if you can identify alternate ways of performing the actions.
For these questions, assume these facts unless otherwise stated: A floppy diskette in drive A contains Lotus 1-2-3 worksheet files (with the extension .wk1), WordPerfect files (extension .wp), and dBase database files (extension .dbf). The computer has a hard drive C, and the prompt is C:\>.
1. Copy all the Lotus 1-2-3 worksheet files from drive A to the \ss directory on drive C.
C:\>cd \ss
C:\SS>copy a:*.wk1
or
C:\>copy a:*.wk1 \ss
or
A:\>copy *.wk1 c:\ss
2. Copy all the WordPerfect data files from drive A to the \wp directory of drive C.
C:\>cd \wp
C:\WP>copy a:*.wp
or
C:\>copy a:*.wp \wp
or
A:\>copy *.wp c:\wps
3. Copy all the dBase data files from drive A to the \db directory of drive C.
C:\>cd \db
C:\DB>copy a:*.dbf
or
C:\>copy a:*.dbf \db
4. Copy the Lotus 1-2-3 files BUDGET? from the \ss directory to the \ss\work directory.
C:\>cd \ss
C:\SS>copy budget?.wk1 \ss\work
or
C:\SS>copy budget?.wk1 work
or
C:\>cd \ss\work
C:\SS\WORK>copy \ss\budget?.wk1
or
C:\SS\WORK>copy ..\budget?.wk1
or
C:\>copy \ss\budget?.wk1 \ss\work
5. Erase the copied worksheet files from the \ss directory.
C:\>cd \ss
C:\SS>del budget?.wk1
or
C:\>del \ss\budget?.wk1
6. Remove the \ss\home and \ss\school directories.
C:\>rd \ss\home
C:\>rd \ss\school
7. Delete all files from the \db directory and remove it.
C:\>cd \db
C:\DB>del *.*
C:\DB>cd \
C:\>rd \db
or
C:\>del \db
C:\>rd \db
8. Copy all the files from the \ss\work directory to the \ss directory and remove the \ss\work directory.
C:\>cd \ss\work
C:\SS\WORK>copy *.* \ss
C:\SS\WORK>cd \
C:\>rd \ss\work
or
C:\>copy \ss\work\*.wk1 \ss
C:\>rd \ss\work
9. Create a new directory structure that looks like this:
|---- lotus
|
\ -------- data -- |
|
|---- wp
C:\>md \data
C:\>md \data\lotus
C:\>md \data\wp
10. Copy all the files from the \ss directory to the new \data\lotus directory.
C:\>copy \ss\*.* \data\lotus
or
C:\>copy \ss \data\lotus
11. Copy all the files from the \wp directory to the new \data\wp directory.
C:\>copy \wp\*.* \data\wp
or
C:\?copy \wp \data\wp
12. Remove the old \ss and \wp directories.
C:\>del \ss
C:\>rd \ss
C:\>del \wp
C:\>rd \wp
Answers to Exercise 4
The first exercises are paper exercises only.
1. Backup all files from the root directory of drive C to drive A.
C:\>backup c:\ a:
2. Backup all files from drive C to drive A.
c:\>backup c:\ a: /s
3. Backup only the new or modified files from drive C to drive A.
C:\>backup c:\ a: /m
4. Your hard drive crashes and you have to replace it. Restore all your files.
C:\>restore a: c:\ /s
5. You accidentally delete a file called C:\data\lotus\budget.wk1. Restore it.
C:\>restore a: c:\data\lotus\budget.wk1
6. Using the directory structure last created (with the directories \data\lotus and \data\wp), backup all your Lotus 1-2-3 and WordPerfect data files.
C:\>backup c:\data a: /s
Perform the next exercises on your computer.
7. Using a blank diskette provided by your instructor, backup the data files in the \data directory of drive C.
C:\>backup c:\data a: /s
8. If you know how to use Lotus 1-2-3 or WordPerfect, follow these steps: 1) Start either program. 2) Retrieve one of the existing data files, make a change to it, and save it again. 3) Create a new data file and save it.
9. Backup only the files in the \data directory that have changed since you last backed up. There should be two files.
C:\>backup c:\data a: /m /s
Answers to Exercise 5
1. Use the chkdsk command to check the status of files on drive C.
C:\>chkdsk
2. If chkdsk reports a problem, did you elect to repair it? What option must you use to get chkdsk to repair errors?
C:\>chkdsk /f
3. Change the disk label of your data diskette in drive A to "BOB"
C:\>label a:
4. Print a directory listing of the root directory of drive C.
C:\>dir c:\ > prn
5. Print the directory structure of drive C.
C:\>tree > prn
6. Capture the directory structure of drive C and all the files on drive C to a disk file called "tree.txt" located on drive A. View this file with the type command.
C:\>tree /f > a:tree.txt
c:\>type a:tree.txt
7. Make an exact duplicate of your data diskette onto a disk that your instructor supplies.
C:\>diskcopy a: b:
8. Suppose your computer has these software programs: WordPerfect installed in C:\wp, dBase IV installed in d:\dbase4, DOS external programs installed in c:\dos, and several batch files installed in c:\dos\batch. Write a path statement to accommodate running these programs from any directory or disk.
C:\>path c:\dos\batch;c:\dos;c:\wp;c:\dbase4
9. Your laser printer is serial, attached to COM1:, and requires settings of 9600 baud, eight data bits, one stop bit, and no parity. Write mode statements to accommodate this printer.
C;\>mode com1: 9600,n,8,1,p
10. Your laser printer is parallel. Write mode statements to accommodate this printer.
No mode statement is necessary for a parallel printer.
Answers to Exercise 6
1. WordPerfect is installed in c:\wp50. Write a batch file that changes to that directory, starts WordPerfect (the command is wp), and returns to the root directory of drive C when finished. Make sure the batch file will work no matter what the current drive and directory are. Call the batch file w.
c:
cd \wp50
wp
cd \
Answers to Exercise 7
1. Modify the existing w batch file so that it passes parameters to WordPerfect. There could be up to five parameters.
c:
cd \wp
wp %1 %2 %3 %4 %5
cd \
2. Modify the existing w batch file so that it hides its action from the user. Have it clear the screen when finished.
echo off
c:
cd \wp
wp %1 %2 %3 %4 %5
cd \
cls
3. Create batch files called mon, wed, and fri to implement the backup strategy discussed earlier.
fri.bat:
backup c:\ a: /s
mon.bat:
backup c:\ a: /s /m
wed.bat:
backup c:\ a: /s /m
Answers to Exercise 8
1. Create a batch file called format that prevents the hard drive C from being formatted. Have the batch file display a message if the user tries to format drive C. If the target of the format is any other drive, go ahead and perform the format. Make sure that the DOS format program receives any parameters passed to it.
echo off
if .%1. == .C. goto error
if .%1. == .c. goto error
format %1 %2 %3 %4 %5
goto end
:error
echo Can't format drive C on this computer
goto :end
:end
2. Discuss how the location of the batch file you just created and the path statement will interact to determine whether this command will work.
If the paths are set so that the directory that this batch fils is in is reached before DOS's format program, the line in the batch file reading "format %1 %2 %3 %4 %5" will run this batch file again. We don't want this.
If the paths are set so that DOS's format program is found first, this batch file never gets run. One solution is to rename the DOS format program to (for example) xformat. The line in the batch file then becomes "xformat %1 %2 %3 %4 %5" Another solution is to set the paths so that this format batch file is found first, with the line in the batch file becoming "c:\dos\format %1 %2 %3 %4 %5"
What is the difference between these two solutions? Is there a situation where the second solution doesn't work?
Table of Contents
Course Objective 1
Storage Measurement 1
Random Access Memory (RAM) 1
Diskette Drives, Hard Disk Drives, Network Drives 3
History of PC DOS 4
Functions of DOS 6
DOS Prompt 7
Using Help 8
Format Command 8
Unformatting A Disk 9
Files 9
Directory (dir) Command 10
Copy Command 11
Moving Files 12
Global File Names 12
Erase or Del Command 13
Undeleting Files 14
Renaming a File 14
Editing DOS Commands 15
Exercise 1 15
Directories and Subdirectories 17
Working With Directories 18
Make Directory Command 20
Exercise 2 21
Change Directory Command 21
Remove Directory Command 22
Exercise 3 22
Using MS-DOS Shell 24
Backup Command 27
Restore Command 28
Backup Strategy 29
Exercise 4 31
Other DOS Commands 31
Internal vs. External Commands 31
The Path Command 32
Check Disk (chkdsk) Command 33
Prompt Command 33
File Attributes 34
Diskcopy Command 35
Xcopy 36
Mode Command 36
Configuring Your Computer 37
The Tree Command 39
Label Command 39
Redirecting Output 39
Exercise 5 40
Batch Files 41
Creating Batch Files 42
Autoexec.bat 43
Exercise 6 43
Commands for Batch Files 43
Exercise 7 46
The Goto Command and Labels 47
The If command 47
Exercise 8 48
Using Edit 48
Using Edlin 50
Answers to Exercise 1 53
Answers to Exercise 2 54
Answers to Exercise 3 54
Answers to Exercise 4 56
Answers to Exercise 5 58
Answers to Exercise 6 58
Answers to Exercise 7 59
Answers to Exercise 8 59
Table of Contents 1