• No results found

Understanding File Attributes

In document Using Ms-dos 6.22 (Page 138-141)

As you will learn later in this chapter, DOS tracks each file on a disk through a directory entry. This entry maintains critical information about the file and where it is stored on disk.

One of the pieces of information maintained in the directory entry is called the file attribute field. This one-byte field stores a number of characteristics about each file but is not dis-played in a normal directory listing. Each characteristic stored in the file attribute field is called a file attribute, and each file can have more than one file attribute. Each file attribute is

5 II

Part

Ch

108 Chapter 5 Understanding Files and Directories

represented in the attribute byte by a single bit, often called an attribute bit. Table 5.3 lists the attributes and their purposes in DOS. You can view and modify most attribute bits by using the ATTRIBcommand; DOS manages some attribute bits directly.

Table 5.3 File Attributes and Their Meanings

Attribute Bit Meaning

Archive When DOS writes to a file, it sets the Archive attribute on. Some DOS commands such as MSBACKUPand XCOPYremove this attribute from files.

Files having the Archive attribute have been altered or created since the last time they were archived.

Hidden This file is bypassed by most DOS file-managementcommands and does not appear in a directory listing. Hidden files, however, are listed by the DOS Shell in the file list area.

Read-only This file can be accessed for information but cannot be erased or modi-fied. (Note that you can erase a read-only file by using the DOS Shell.) Subdirectory This attribute identifies the entry as a directory rather than a standard file.

System This file is a DOS system file.

Volume Label This entry is the volume label for a disk. The entry does not identify an actual file.

The Archive attribute works with DOS file-management commands to determine which files the commands process. The MSBACKUPcommand resets the Archive attribute of any file it copies to disk. As you work with the files on your disk, each file on which DOS performs a write operation gets flagged with the Archive attribute, which signals that the file has changed since it was last archived. If you have a recent full-disk backup, you can create a backup of only the files that have changed since the last backup by telling MSBACKUPthat you want to copy only files having the Archive attribute.

A file entry with the Hidden attribute turned on is “invisible” determineto most DOS file-management commands. Hidden files have filenames and extensions like normal user files but are not processed by the DIRand COPYcommands. The two DOS system files on the boot disk are examples, as are the files that manage a DoubleSpace drive.

You can detect the presence of hidden files by using the ATTRIBor CHKDSKcommand. Using

ATTRIB, you also can list hidden files. CHKDSKmerely indicates the number of hidden files on the disk.

The Subdirectory attribute indicates to DOS that the entry is not intended for a user file but for an additional directory called a subdirectory. When it carries out file-management commands, DOS knows to bypass a file with the Subdirectory attribute turned on.

The System attribute indicates that a file is an operating system file. The two DOS system files have this attribute in addition to the Hidden attribute. You need not worry about the System attribute; it does not affect your DOS work.

Introducing the DOS File System 109

The Volume Label attribute indicates that the directory entry involved is to be used as the name of the volume, not as a filename. DOS then combines the filename and extension fields to provide an 11-character volume label for the disk. Only a Volume Label entry can have this attribute set (turned on).

The Archive, Hidden, Read-only, and System attributes are the only attributes you can change directly through DOS. DOS controls the other attributes without your intervention.

Changing File Attributes with the ATTRIBCommand

DOS’s ATTRIBcommand provides the means to change the settings of the Archive, Read-only, Hidden, and System attributes. The syntax of the ATTRIBcommand is

ATTRIB [+R|-R] [+A|-A] [+S|-S] [+H|-H] filespec [/S]

If you issue the ATTRIBcommand with no parameters, you get a list of all the files in the cur-rent directory, along with a display of their attribute status. Figure 5.1 shows a typical result.

5

As you can see in the figure, all the files have the Archive attribute set on. Also, all the files whose names begin with the letters R and G are marked as Read-only.

To change the attributes of files, use the first letter of each attribute’s name and a plus (+) sign to set the attributes on or a minus (–) sign to set the attributes off. You can have any logical combination on one command line, such as the following:

ATTRIB -A +R Figure 5.1

TheATTRIBdisplay when no parameters are given.

110 Chapter 5 Understanding Files and Directories

The preceding example turns off the Archive attribute and turns on the Read-only attribute for every file in the current directory. You can narrow the scope of the ATTRIBcommand by specifying a pathname expression (drive, path, and wildcards are honored) on the command line, as in the following:

ATTRIB -R G*.*

This example removes the Read-only attribute from only those files whose names begin with G. (You get a heavy dose of pathname expressions later in this chapter.)

You also can widen the scope of the ATTRIBcommand by using the /Sswitch. If you give

ATTRIBa pathname expression as a parameter, by default the actions are limited only to the specified path. Giving no pathname expression to ATTRIBlimits its action to the currently logged directory. Using the /Sswitch widens the scope of the ATTRIBcommand to include any directories under the directory where ATTRIBbegins its actions.

Establishing Read-Only Files

The ATTRIBcommand gives you control over file attributes. In particular, the Read-only attribute makes DOS unable to overwrite a file. DOS commands such as EDIT, COPY, DEL, and XCOPYare capable of changing the data contained in a file. Files with the Read-only attribute cause a message to appear, telling you that the command you have tried to use cannot provide the service you are wanting.

In practice, however, the Read-only attribute has become little more than a confirmation flag to many modern programs. Both the DOS Shell and Windows File Manager can erase files having the Read-only attribute, for example, but only after you confirm that it is okay.

To give files the Read-only attribute, use the +Rparameter, as in the following:

ATTRIB +R F:\WSTAR\*.TXT

Using the -Rparameter has exactly the opposite effect, that of removing the Read-only flag.

TheFDISKandFORMATcommands command do not observe the read-only status of a file.FDISKandFORMATare disk-level commands; therefore, they don’t look at disk directories when they are doing their jobs. Don’t rely on the Read-only attribute of a file to protect the file from a disk-level command. Use the disk’s write-protect tab to prevent floppies from being destroyed with FDISKandFORMAT.

In document Using Ms-dos 6.22 (Page 138-141)