Attrib

Index

The Attrib command is used to display, set, or remove one or more of the four attributes (read-only, archive, system, and hidden) that can be assigned to files and directories. It is typically used to remove read-only, hidden, and system attributes so a file can be moved or deleted -- or to set them so that it can't.

Syntax:

To display the attribute settings of all files in the current directory:
ATTRIB

To display the attributes of a directory:
ATTRIB directoryname

To display the attributes of a file:
ATTRIB filename

To set or remove attributes of a file or directory:
ATTRIB [ + | - R] [ + | - A] [ + | - S] [ + | - H] [directory|filename] [/S]

+ Sets an attribute. - Clears an attribute.
RRead-only file attribute.
AArchive file attribute.
SSystem file attribute
HHidden file attribute.
/SProcesses files in all directories in the specified path.

Notes:

  1. The Archive attribute is automatically set when a file is saved to disk. Backup programs (and XCOPY with the /M switch) target these files as "not backed-up". After the files have been copied, the archive attribute is removed to indicate the file is now "backed-up".

    The Read-Only attribute allows a file to be accessed but not modified.

    The System attribute is normally reserved for files that are necessary for Dos/Win95 to load properly.

    Files and directories with the Hidden attribute set are not normally displayed in directory listings or Open Files dialogue boxes. The usual reason for hiding folders is because they are important to system or program operation and should not be deleted or moved in casual tidup operations. Hidden (and System) folders will often also have the Read-Only attribute set.

  2. Multiple attributes can be set/cleared by combining switches (separated by spaces).

  3. Although both files and directories can have attributes assigned and cleared using ATTRIB, there are differences in the way they behave - the most obvious of which is that wildcards (? and *) can be used to display or change the attributes for a group of files whereas directories must be named in full.

  4. Setting a file's System, Hidden, or Read-Only attribute will prevent the file from being deleted or moved using DEL, ERASE, or MOVE commands but will not protect the files from DELTREE or FORMAT.

  5. Although a directory's Read-Only attribute can be set, this seems to serve little purpose. Firstly, the attribute only applies to the directory and NOT the files within it. Furthermore, setting a folder to read-only does not prevent it being deleted using RD (ie in Dos, setting a folder to read-only offers NO protection against deletion) and doesn't stop it being moved with MOVE either. In Win95 Explorer it will cause a warning notice to be displayed before the folder is deleted - which is something, I suppose.

  6. Windows Explorer (Win9x) does not show folder attributes in the general listings, but they can be viewed (and changed) via the File|Properties menu when a particular folder is selected.

  7. File Manager (from Win3.1) does show file archive and read-only attributes but hidden files are, indeed, hidden. The attributes of selected files or directories can be changed via the File|Properties dialogue.

  8. Win9x offers limited support to the attribute concept: An extra warning message is given when attempting to move or delete a file with the Read-Only attribute set, and Windows Explorer can be set to show or ignore Hidden files as the user wishes.

Examples:

To display the attributes of a file named "news86":
ATTRIB news86

To assign the Read-Only attribute to the file "report.txt", use:
ATTRIB +R report.txt

To remove the System and Hidden attributes from "record.txt":
ATTRIB -S -H record.txt

To hide the directory "c:\secret:"
ATTRIB +H c:\secret

To hide the files (but not the directories) in the C:\ directory:
ATTRIB +H c:*.*

In Addition ...

ATTRIB can be used to find/list files in much the same way as DIR but in a rather different format. For example, to list all files named "Readme.txt" on the c: drive:
ATTRIB c:\readme.txt /s
will display:


C:\WINDOWS>ATTRIB c:\readme.txt /s
  A          README.TXT;    c:\WINDOWS\HELP\README.TXT
  A          README.TXT;    c:\PROGRA~1\NETSCAPE\README.TXT
  A          README.TXT;    c:\PROGRA~1\PPP-BO~1\readme.txt
  A          README.TXT;    c:\PROGRA~1\SBCD\README.TXT
  A          README.TXT;    c:\PROGRA~1\NORTON~1\README.TXT
  A          README.TXT;    c:\PROGRA~1\MICROS~3\POWERT~1\README.TXT
  A          README.TXT;    c:\SCSI\README.TXT
 
C:\WINDOWS>_

The output is in the following format:
Column 3: Archive attribute: "A" indicates set, space indicates not set.
Column 6: System attribute: "S": set; space: not set
Column 7: Hidden attribute: "H": set; space: not set
Column 8: Read-only attribute: "R": set; space: not set
Column 14: Filename plus extension in Dos short form.
Column 28: Full path.

It is interesting to note that full path name is in mixed long- and short-filename formats. It would seem that long-filenames are used for the actual file and any specified directories (with or without wildcards). Sub-directories included through using the /s switch are in short-filename format.

Exit Codes:

0No errors occured.
1The source file couldn't be opened/located.
2?
3Execution was terminated by Ctrl-C before the operation was complete.

File Details:

File NameDefault LocationDos Ver.Win Ver.SizeDateSource
Attrib.exec:\windows\command 7.0Win95 15,252111/07/95win95_02.cab
7.1Win95 (OSR2.x) 15,252224/08/96win95_02.cab
Win98 15,252211/05/98win98_40.cab
Win98 SE 15,252223/04/99win98_44.cab

Superscripts denote which same size files, if any, are identical (using FC).


This page last revised:
August 24, 2000