• No results found

Understanding Filenames

In document Using Ms-dos 6.22 (Page 132-135)

DOS ensures that every one of your files has a name. In fact, DOS does not provide a way to put file data on a disk without a filename. When a file is created, either by your software or a DOS file service routine, information about the physical location of the file is stored in a File Allocation Table (FAT), which is similar to a book’s table of contents. DOS places the

5 II

Part

Ch

102 Chapter 5 Understanding Files and Directories

name of each file and its attributes in a special structure called a directory, which you can think of as the chapter headings of a book. Using this analogy, you can think of files as the pages in each chapter.

For now, however, you need only concern yourself with the names of files. You learn more about the other parts of the DOS file system later in this chapter. Keep in mind that a direc-tory is a special structure used to store filenames and files. Later in this chapter, you learn more information about the directory.

Creating Filenames

The characters you see on your computer screen are the ASCII code representations of bytes of data. One character is stored in one byte. In a disk directory, each slot where a file-name can be stored reserves a space 11 bytes long (8 for the first part of the filefile-name plus 3 for the extension). DOS accepts for filenames most characters that you use for “everyday”

names. You can use the uppercase and lowercase letters A through Z; DOS automatically stores letters in uppercase in a directory entry. You also can use the numeric characters 0 through 9 and many punctuation characters not used as separators in the file system.

Following are the rules for creating legal filenames:

Each filename on a disk must be unique.

Filenames, even though they are not always expressed that way, include the drive letter and directory path of the file. In practical terms, this naming convention means that each file in a directory must have a unique name because the difference in directory names adds to a filename’s uniqueness.

A filename consists of the following items:

• A name of one to eight characters

• An optional extension of one to three characters

• A period between the name and the extension (if an extension is used)

The following characters are allowed in a filename:

• The letters A through Z (lowercase letters are transformed into uppercase auto-matically)

• The numerals 0 through 9

• The following special characters and punctuation marks:

$ # & @ ! ( ) - { } ‘_ ~ ^ ‘

DOS reserves certain ASCII codes for other uses and does not let them be a part of the filename. The following characters are not allowed in a filename:

• Any control character (ASCII codes used as commands)

• The space character

• The following special characters and punctuation symbols:

= / [ ] “ : ; , ? * \ < > |

Introducing the DOS File System 103

To understand why DOS disallows the use of some characters in filenames, you must look below the surface of DOS. Certain characters are not allowed because DOS does not pass those characters from the keyboard to the command or external command program that controls a file’s name. You cannot, for example, use the Ctrl+G (^G) character in a filename because Ctrl+G tells an input device to sound the computer’s bell or beep signal. DOS does not accept the Escape character, produced by the Esc key, as part of a filename because DOS interprets the Esc key as your request to cancel the command line and start again.

Another example of an unacceptable character is Ctrl+S (^S), which DOS and other operat-ing systems use to stop the flow of characters from the input device to the output device.

Ctrl+S stops screen scrolling, for example. If you press Ctrl+S while entering a filename, DOS assumes that you are entering an input-stopping character, not part of a filename.

You cannot use in a filename any characters that COMMAND.COMand external command pro-grams use to divide the parameters and switches from the command in a command line.

Because DOS must parse (distinguish the various components of) the command line, certain characters are seen as delimiters of parameters or as parts of a parameter. The backslash character (\), for example, separates directory names in a path specifier. DOS always reads a backslash in a command line as part of a path.

Avoiding Reserved Names

One of the ways in which DOS is able to control so many different types of devices is by using a logical device. It is important to understand that each of these devices has a name that is reserved and cannot be used for other purposes.

In theory, DOS treats all the input and output devices it controls as if they were made out of software. Such devices include almost everything you think of as belonging to a computer system—disks, printers, keyboards, screens, and modems.

The PC manufacturers are responsible for accepting and generating data in a fashion that conforms to DOS standards. The actual control over the actions of a device (print heads, disk drive motors and heads, and so on) is left to programming contained on ROM chips incorporated into the devices. Thus, DOS needs to know only that a printer exists and that the printer is connected to the system in a specific way, normally via a parallel or serial port.

To you, a parallel port is a hardware connector where you plug in a cable. To DOS, the par-allel port is simply an address in memory where it sends and receives data. Each of these addresses is called a logical device and is given a name. By default, DOS expects to see a printer connected to the first parallel port, which it calls LPT1.

The first available disk is A:. By convention, B: is reserved for the second floppy disk, and C:

is reserved for the first hard disk volume. The keyboard and video card are combined to cre-ate a logical device named CON:.

Notice that all these logical device names end with the colon (:). The colon signifies that something is a DOS logical device. In some contexts, however, the colon is omitted, as in this example:

COPY CON SUMFILE.TXT

5 II

Part

Ch

104 Chapter 5 Understanding Files and Directories

This variation of the COPYcommand tells DOS to take input from the console (CON:) and save it to the currently logged drive and directory as a file having the name SUMFILE.TXT. What does all this talk of logical devices have to do with filenames? Simply, DOS’s internal routines treat logical devices like files in many ways. That’s why when you try to name a file with a name for a logical device, DOS gets confused and weird things can happen, such as losing data or sending a file to a printer.

For this reason, DOS reserves names for its logical devices. DOS can treat some of these log-ical PC devices in a high-level way by accepting their names as input or output parameters in a command line, as in the preceding example. Before it uses the filename parameters in a command line to look for a file, DOS checks to see whether the filename is a device name.

Table 5.1 lists the major logical DOS input and output device names and their purposes.

Table 5.1 DOS Device Names

Device Name Purpose

COMx or AUX Identifies a serial communication port (x can be the number 1, 2, 3, or 4).

LPTx or PRN Identifies a parallel printer port (x can be the number 1, 2, 3, or 4).

CON Identifies the screen and keyboard.

NUL Identifies the “do nothing” device, also called a bit bucket. Output sent to NUL is not displayed, stored, or acted on in any way.

CLOCK$ Provides date and time services.

Never attempt to write a disk file with a name that is the same as one of the device names listed in Table 5.1. DOS intercepts the device name, even if you add an extension, and tries to use the device—not the file you intend—to complete the command. Use a device name only as a device parameter in a command.

In document Using Ms-dos 6.22 (Page 132-135)