One of the most useful (and coolest) Microsoft-provided components for use with ASP pages is the FileSystemObject. This object, as its name implies, allows programmatic access to the Web server's filesystem. There are a number of objects that are included with FileSystemObject, such as the File, Drive, and Folder objects, which contain specific information about a particular aspect of the filesystem. If you are unfamiliar with the FileSystemObject and its related objects, I highly suggest that you check out the following resources before continuing on with this article:
- FileSystemObject FAQs @ ASPFAQs.com
- Reading Files with the FileSystemObject
- Writing Files with the FileSystemObject
- Copying, Moving, and Deleting Files
- Iterating through the FileSystemObject Collections
There are a number of good articles on the FileSystemObject here on 4Guys and all over the Net;
regardless, there are certain properties of various FileSystemObjects that don't get much press. One of those
is the Attributes
property of the File object, which can be used to read and modify the
various attributes of a file on the Web server. The file attributes revealed by the Attributes
property include whether a file is Read-Only, a System File, a Hidden File, a directory, if it's compressed,
if it's archived, etc.
The Attributes
property compresses all of this information about a file into a numeric value ranging
from zero to 255. For example, the following code produces a value of 32
:
|
I'm sure you're wondering what the hell that means! :-) Well, to understand what various
Attribute
values mean, we have to consult the following table:
Attribute Values | ||
---|---|---|
Attribute | Value | Description |
Normal | 0 | No attributes set. |
Read-Only | 1 | Read-only file. (Attribute is read/write.) |
Hidden | 2 | File is a hidden file. (Attribute is read/write.) |
System | 4 | A system file. (Attribute is read/write.) |
Volume | 8 | Disk drive volume label. (Attribute is read-only.) |
Directory | 16 | The file is a directory. (Attribute is read-only.) |
Archive | 32 | File needs to be archived (i.e., it has changed since the last backup). (Attribute is read/write.) |
Alias | 64 | The file is a shortcut (link). (Attribute is read-only.) |
Compressed | 128 | File is compressed. (Attribute is read-only.) |
So, in the demo example, /index.shtml
has only one
of these properties set, Archive. If it had also been, say, Read-Only, then the value of the Attributes
property would be the sum of the two properties (33
). So, to determine a given file has
a given attribute, you can use the bit-wise AND (AND
) operator like so:
If (objFile.Attributes AND AttributeValue) then
|
The code below provides a function to view the file attributes for a given file. There's also a live demo to try out. In Part 2 we'll examine how to alter a file's attributes programmatically!
|