Setting File Attributes

If you're comfortable enough with the MS-DOS filesystem, you can leverage some of its lesser known capabilities. You can control whether a file can be seen and/or written to. This can be useful if you do not want to overwrite a template file that is to spawn multiple derivatives, or your system is used by multiple lizards and you do not want a file to be seen through a normal DIR operation.

File attributes are stored alongside files and do not affect their contents. The possible file attributes are denoted by letters when you run the ATTRIB command:

Read Only

When this attribute is set on a file, any attempts to write to it will fail, as if it was on a write-protected disk.

Note: While the Read Only attribute can be useful to prevent undesired writes, it is merely a deterrent. Anyone can remove the attribute and make changes to a file if they can use the ATTRIB command. If you need actual security in your files, consider getting Windows NT.


This prevents the file from being seen in directory listings. You can still find it if you use the command DIR /A (/A without an extra parameter assumes you want to list all files regardless of attributes). Even if a file is hidden, you can still access it and write to it unless R is also set.


This indicates the file is a system file and is mostly assigned to specific files by MS-DOS to protect them from being deleted. Files with the S attribute set are often done so in combination with H and R. Any attributes cannot be set or unset unless S is also unset.


This attribute indicates a file is ready for archiving, and can be utilized in makeshift backup routines using XCOPY. Usually you do not need to manage this attribute itself, as MS-DOS will take care of that for you as needed.

The ATTRIB Command

A command exists specifically to manage file attributes, called ATTRIB. When used on its own, it merely displays the attributes of files in a directory. The following screen shows file attributes in the root of a minimal MS-DOS installation:

     SHR      C:\IO.SYS
     SHR      C:\MSDOS.SYS
       R      C:\COMMAND.COM
       R      C:\WINA20.386
  A           C:\AUTOEXEC.BAT
  A           C:\CONFIG.SYS
  A           C:\TEST.TXT

A few of the files have the Read Only attribute set to prevent modifications to them, as they are essential to the system's operation. Two of these also have the System and Hidden attributes set to obscure them from normal viewing.

You should not modify the attributes of these system files unless you know what you are doing. Instead, create a file called TEST.TXT and use that to experiment with file attributes and their effects. Add some text to this new file, save it and quit your text editor, then run the following command to prevent writing to it:


The + symbol indicates you want to set the specified attribute on said file. When you open this file and try to save new contents to it, the operating system will not allow you to because the Read Only attribute has been set. To unset the Read Only attribute, use a - symbol instead:


To hide a file from normal directory listings, use +H on TEST.TXT. Then, try running DIR TEST.TXT; you'll get a message saying File not found. But if you run DIR /A TEST.TXT, you will be able to see the file listed. When you're done, unset the Hidden attribute.

Note: Directories can have attributes as well, but don't show up in ATTRIB listings. This can make it difficult to find a hidden directory. Try using DIR /A or ATTRIB /S | MORE if you suspect a hidden directory exists. You can then use the ATTRIB command on this directory you've found to see what attributes it has set, or change them.

You should not ever need to set the System and Archive attributes on files yourself, as those are handled by the operating system and various programs appropriately.

Back to main page