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.
To display the attribute settings of all files in the current directory:
To display the attributes of a directory:
To display the attributes of a file:
To set or remove attributes of a file or directory:
ATTRIB [ + | - R] [ + | - A] [ + | - S] [ + | - H] [directory|filename] [/S]
+ Sets an attribute. - Clears an attribute.
|R||Read-only file attribute.|
|A||Archive file attribute.|
|S||System file attribute|
|H||Hidden file attribute.|
|/S||Processes files in all directories in the specified path.|
- 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.
- Multiple attributes can be set/cleared by combining switches (separated by spaces).
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
To display the attributes of a file named "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
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
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.
|0||No errors occured.|
|1||The source file couldn't be opened/located.|
|3||Execution was terminated by Ctrl-C before the operation was complete.|
|File Name||Default Location||Dos Ver.||Win Ver.||Size||Date||Source|
Superscripts denote which same size files, if any, are identical (using FC).