[ Back to Table of Contents ]
[ << ]
[ >> ]
XXCOPY TECHNICAL BULLETIN #06
From: Kan Yabumoto firstname.lastname@example.org
To: XXCOPY user
Subject: File Attributes: what are they and how to use them.
Since XXCOPY has features which interact with the file attributes,
a discussion of XXCOPY cannot be complete without touching the basics
of the file attributes. This article presents the fundamentals of
the file attributes and how XXCOPY manipulates them. In addition,
some common techniques with the file attributes are discussed.
What are the file attributes?
The operating systems (DOS, Win95/98, WinNT/2000/XP) maintain certain
properties associated with every file and directories in addition to
the file contents (data inside the file). Such properties include
file size in bytes
file date/time (creation time, last-modify time, last-access time)
archive bit (shows that the file has not been archived yet)
read-only bit (write-protect the file)
directory bit (distinguishes a directory from a file)
hidden bit (hides from an ordinary directory listing)
system bit (denotes a system file whatever that means)
These properties are mostly maintained by various components of
the operating system and they are handled automatically. So,
the users may not be concerned with them. However, manipulating
some of the properties are not very difficult and it can even be
quite useful at times. This article shows some common techniques
associated with the file attributes.
The file size is always determined by the actual size of the file
and the only way to change it is to increase by appending more
bytes to the existing file, or to decrease by overwriting with a
shorter file. The file date/time can be more easily changed.
Since changing any of the three date/time values is supported by
Win32 file I/O API, one can write a program to change them. In fact,
there are many utility programs available to do so. Here, we will
discuss the file attributes with greater details.
What is the file attributes?
Although one can say the file size and the file date/time are file
attributes (i.e., any properties associated with a file other than
the file contents), with the more narrow definition and popular
usage, the file attributes are collection of flags stored as a bit
mapped 32-bit quantity which describes various aspects of the file.
The original MS-DOS file attributes had only 8 bits in the file
attributes, the Win32 file attributes are stored as a 32-bit quantity.
Although the exact bit positions of the file attributes are not
officially guaranteed to remain the same by Microsoft, they will
probably never be changed.
Bit 0 Read-Only
Bit 1 Hidden
Bit 2 System
Bit 3 Volume Label
Bit 4 Directory
Bit 5 Archive
Bit 3 (Volume Label) was used in MS-DOS to store the volume label
just like an ordinary file in the directory. Bit 4 (Directory)
distinguish a file from a directory. These two bits cannot be
modified easily. But, the remaining four bits (bit 0, 1, 2, and 5)
can be examined and/or modified by the ATTRIB.EXE utility which is
supplied by DOS/Windows.
The official Microsoft's way to manipulate the file attributes.
Windows 95/98 provide a system utility program, ATTRIB.EXE which
is usually stored in the C:\Windows\command\ directory.
Here is the ATTRIB utility's command syntax
ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] filespec [/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.
For example if you want to clear the Archive attribute bit of all
the files in a directory, execute the following command line.
ATTRIB -A c:\mydir\*
The Read-Only attribute.
This bit is useful to make a file write-protected by software.
For example, by setting the \AUTOEXEC.BAT file Read-only, you may
protect the file from accidental deletion. Or you may set a
few files with the Read-only attributes and delete all the files
using a "DEL *" (Delete all) command, the read only files will
not be deleted under normal circumstances. Certain files in the
Win95/98 system are kept as Read-only by default (e.g., the system
Before you can delete or overwrite a Read-only file, you must
remove the Read-only file attribute bit.
XXCOPY can force overwriting (or deletion) of a Read-only file by
the /R switch.
The Hidden and System attribute.
The purpose of the Hidden attribute bit is to make the file
invisible in certain applications' file list display. Since many
file applications has the feature to ignore the Hidden attribute
bit, the file with the Hidden attribute bit is not always invisible.
The System attribute bit is probably the least rigorously
defined in its usage. From the early days of MS-DOS, the System
attribute bit has been used in inconsistent manners that the bit
seldom has much meaning. The DIR command treat the System
attribute similarly to the Hidden bit for directory listing.
But, the COPY command does not care whether a file has the System
attribute or not for copying it (Interestingly the DIR and COPY
commands are both "built-in" commands which is implemented within
the COMMAND.COM program).
In most Win95/98 systems, you will find about twenty files in the
root directory which are marked both Hidden and System. These two
attributes are often go hand in hand. But, the choice seems
While the usage of the Hidden and the System attribute bits are
not well defined, the presence (or absence) of these attribute
bits seldom change the actions of most system utilities except for
the DIR and COPY commands, in most case, removing the Hidden and
System attributes on most files do not cause any harm (except
maybe some layer of protection from accidental erasure).
XXCOPY by default (/H0) ignores a file with either Hidden or System
attribute. With the /H switch, you may include files with the
Hidden or the System attributes in XXCOPY's copy action.
The Archive attribute.
The Archive attribute was first introduced by MS-DOS version 2.0
when the XCOPY utility was also created. Therefore, the Archive
attribute is probably best explained by how XCOPY handles the
Archive attribute. The purpose of the Archive attribute was clearly
to quickly determine whether a file requires a back up (archiving).
The Archive attribute is set whenever an existing file is either
overwritten or modified (i.e., renamed or moved to another directory)
by the file system. A new file is usually created with the Archive
attribute set. The idea is to have a utility or application program
to take the responsibility of clearing the Archive bit when a
file is successfully backed up. The next system backup operation
will be made much more efficient by focusing only on the files with
the Archive attribute bit set which are either newly created or
modified in any way since all the Archive attributes are cleared the
last time (i.e., the last backup time).
Incremental Backup using the Archive attribute.
When XCOPY was the only "officially" designated system archive utility
in MS-DOS, the Archive attribute had its usefulness. Or, if only
one backup regime in the system manipulates the Archive attribute bit
and no other programs modifies the bit, the scheme works well.
However, there are many backup and archive utilities that are
capable of clearing the Archive attribute.
Unfortunately, the operating systems do not enforce this
"only-one-program-can-modify-the-Archive-bit" policy. Because of
possible interference with other applications which might clear the
Archive attribute, we consider that the incremental backup scheme
based upon the Archive attribute too risky to depend upon.
Therefore, we do not recommend the use of the /M switch to perform
any system backup operation. For an incremental backup, XXCOPY's
/BI switch performs similar function with more confidence by
comparing the files in the source and the destination with regard
to the file size AND file date/time. If either of the two does not
match (or the file does not exist in the destination), the file will
be copied. This method is nearly as efficient as looking at the
Other usage of the Archive attribute.
1. You can determine which file(s) an application makes file
changes (creation and modification) in a directory. First,
clear the Archive attribute of all the files in the given
directory and run the application. Then, check to see which
files are marked by the Archive attribute.
E.g.: ATTRIB -A c:\mydir\* // clear the A bit first
Run your application next
XXCOPY C:\mydir\* /A/L // list files with A bit set
2. Say, you have a directory with many files which you want to
copy to a set of diskettes (one diskette cannot hold all of
the files). You can first set all the files with Archive
attribute set first. Then, run XXCOPY /M (or XCOPY /M). The
copy job will terminate as soon as the diskette becomes full.
But the files which has already been copied are cleared of the
Archive attribute. So, run the same XXCOPY /M command again
with a new diskette. This time, the files which has been copied
will be skipped. Just repeat this operation until the files
with Archive attribute run out.
E.g.: ATTRIB +A C:\mydir\* // set the A bit set
XXCOPY C:\mydir\* A:\ /M // copy files with A bit
XXCOPY C:\mydir\* A:\ /M // repeat for next diskette
... // continue until all files
... // are copied.
Full Backup using the Archive attribute.
We have stated that the use of the Archive attribute is not suitable
for a reliable incremental backup. However, once we abandon the
notion that the Archive attribute serves as a persistent marker, it
becomes even more useful. Yes, the Archive bit as a temporary marker
can be quite convenient. The example in the preceding section of
directory-copy to a set of diskette is a backup in a small scale.
When you run Microsoft's ATTRIBUTE utility,
ATTRIB +A C:\* /S
You will encounter the following messages:
Not resetting hidden file C:\WINDOWS\...
Sharing violation reading drive C
Abort, Retry, Fail?
In this case, entering "F" should let you continue. But, apparently,
the ATTRIB utility treats the "Fail" option as "Abort". This is
provably a bug in the Microsoft program.
Our XXCOPY behaves more predictably.
XXCOPY C:\* /S /AA
The /AA and /AZ switches make XXCOPY to perform the same function
similar to the ATTRIB utility does except it does a better job.
XXCOPY's /AA switch sets (/AZ clears) the Archive attribute bit
including the hidden files (it has automatically set the /H switch
to include hidden files) and handles share-violation gracefully.
If you need speed, you may suppress the console output by /Q or /Q2.
XXCOPY C:\* /S /AA /Q ;shows only the files which changes
XXCOPY C:\* /S /AA /Q2 ;shows only statistics at the end
After setting the Archive attribute bit of all the files in the
volume, you can start repeated backup using the /M switch
XXCOPY C:\* T:\mybackup /S /M /H ...
(change the target media when it is full and try again)
You may apply the same basic technique to a full-scale volume backup
using the Archive attribute. This is quite useful when you are
backing up a large volume into smaller removable medium
(e.g., CD-R, CD-RW, Tape-based file system, or even floppy disk).
If you have an AutoLoader tape drive (e.g., HP SureStore 12000),
a working batch file example based on this scheme is available at
List of XXCOPY's file attributes related switches.
/A0 Cancels *ALL* /A, /M, /AT, and /AX switches.
/A Excludes files without Archive bit set
/AC Ignores the Archive bit (always clears Archive bit)
/M Excludes files without Archive bit set (clears Archive bit)
/AA Sets the src file archive bit (without actually copying)
/AZ Clears the src file archive bit (without actually copying)
Note: Both /AA and /AZ implicitly set /H (can be overridden)
Hidden and System bit
/H0 Excludes files with Hidden or System Attributes bits (default)
/Ho Excludes files without Hidden or System Attributes bits.
/H Ignores the Hidden or System Attributes bits
Destination Read Only bit
/R0 Excludes a file when it exists in dst as read-only (default)
/R Allows overwrite/delete of a read-only file if necessary
Destination file attributes
/K0 Keeps H-bit and S-bit, sets A-bit, clears R-bit (default).
/KS Keeps the source attributes including the read-only bit.
/KD Keeps the attributes of destination (overwritten) file
/KN Sets the destination attributes to normal (only the A-bit)
© Copyright 2015 Pixelab All rights reserved.