Home > Commands A-M > Commands A

ATTRIB


Description | Syntax | Parameters | Switches | Related | Notes | Examples | Errorlevels | Availability

Displays or changes file attributes.

This command displays, sets, or removes the Read-Only, Archive, System, and Hidden attributes assigned to files or directories.


Syntax

ATTRIB /?

ATTRIB [+A | -A] [+H | -H] [+R | -R] [+S | -S] [[drive:][path]filename] [/S [/D]]

Display all attributes of all files in the current directory:

ATTRIB


Parameters
drive: (v3.0 Win95 NT3.5)
Specifies the drive location of file(s) you want to process.
path (v3.0 Win95 NT3.5)
Specifies the path location of file(s) you want to process.
filename (v3.0 Win95 NT3.5)
Specifies the name of the file(s) you want to process.

Switches
/? (NT4)
Display help.
+A | -A (v3.20 Win95 NT3.5)
+A Sets the Archive file attribute.
-A Clears the Archive file attribute.
/D (NT2000)
Processes directories as well.
+H | -H (v5.0 Win95 NT3.5)
+H Sets the Hidden file attribute.
-H Clears the Hidden file attribute.
+R | -R (v3.0 Win95 NT3.5)
+R Sets the Read-only file attribute.
-R Clears the Read-only file attribute.
+S | -S (v5.0 Win95 NT3.5)
+S Sets the System file attribute.
-S Clears the System file attribute.
/S (v3.30 Win95 NT3.5)
Processes files in the current directory and all of its subdirectories.

Related

XCOPY - copying files and directories with different attributes.


Notes
Combining the Hidden and System attributes

If a file has both the Hidden and System attributes set, you can clear both attributes only with a single ATTRIB command. For example, to clear the Hidden and System attributes for the RECORD.TXT file, you would type:

    ATTRIB -S -H RECORD.TXT

Using ATTRIB with groups of files

You can use wildcards (? and *) with the filename parameter to display or change the attributes for a group of files. If a file has the System or Hidden attribute set, you must clear that attribute before you can change any other attributes for that file.


Changing the attributes for a directory

You can display or change the attributes for a directory. To use ATTRIB with a directory, you must explicitly specify the directory name; you cannot use wildcards to work with directories. For example, to hide the directory C:\SECRET, you would type:

    ATTRIB +H C:\SECRET>

Affects only files, not directories:

    ATTRIB +H C:*.*

Viewing archive attributes

The Archive attribute (A) is used to mark files that have changed since they were previously backed up. The BACKUP, RESTORE, and XCOPY commands use these Archive attributes.


The comma shortcut

UNDOCUMENTED Removes attributes of all files in the current subdirectory:

    ATTRIB,

this is the same as:

    ATTRIB -A -H -R -S *.*

Examples

To display the attributes of a file named NEWS86 located on the current drive, type:

    ATTRIB NEWS86

To assign the Read-Only attribute to the file REPORT.TXT, type:

    ATTRIB +R REPORT.TXT

To remove the Read-Only attribute from files in the \PUBLIC\JONES directory on a disk in drive B and from files in any subdirectories of \PUBLIC\JONES, type:

    ATTRIB -R B:\PUBLIC\JONES\*.* /S

As a final example, suppose you want to give an associate a disk containing all files in the default directory on a disk in drive A except files with the .BAK extension. Because you can use XCOPY to copy only those files marked with the Archive attribute, you need to set the Archive attribute for those files you want to copy. To do this, you would use two commands to set the Archive attribute for all files on drive A and then to clear the attribute for those files with the .BAK extension:

    ATTRIB +A A:*.*
    ATTRIB -A A:*.BAK

Next, use the XCOPY command to copy the files from the disk in drive A to the disk in drive B. The /A switch causes XCOPY to copy only those files marked with the Archive attribute:

    XCOPY A: B: /A

If you want XCOPY to clear each file's Archive attribute after it copies the file, use the /M switch instead of /A:

    XCOPY A: B: /M

Errorlevels
Availability
External
DOS
v3.0 v3.20 v3.05 v3.1 v3.21 v3.25 v3.30 v3.3A v3.3R v3.3T v3.31 v3.40 v4.0 v4.01 v4.01A v5.0 v5.0A v5.00.02 v5.001A v5.01 v5.02 v6.0 v6.10 v6.2 v6.21 v6.22 v6.23 v7.00 v7.0R1 v7.10 v8.00
Windows
Win95 Win98 WinME
Windows NT
NT3.5 NT4 NT2000 NTXP NT2003