In Part 1 we looked at how to read and interpret the Attributes
property of the File object (one of the FileSystemObject objects). In this part we'll look at how to use
the Attributes property to programmatically alter the attributes for a file on the Web server!
Recall from the table in Part 1 that there are certain attributes marked and read/write (while others are marked as read-only). As you may have guessed, those marked read/write are values that can be altered by a developer.
The easiest way to add or remove an attribute from a file is to simply add or subtract the appropriate
value from the Attributes property. That is, if you want to make a read/write file read-only, all you
have to do is add 1, the value of the Read-Only attribute, to the Attributes
property. To toggle off an attribute, simply subtract its value from the Attributes property.
When using this method there is one huge caveat. If you are going to add some value to the
Attributes property (in order to "turn on" a particular attribute), you must first make
sure that it does not already possess that value! So, if you wanted to write a function that would make
a specified file read-only, you could use the following code:
|
That's it! Note that you must check to see if a file has a particular attribute before adding the
attribute's value to the Attributes property! Similarly, if you wish to "turn off" an
attribute for a given file, you would want to make sure that the file HAD that attribute BEFORE subtracting
the attribute's value from the Attributes property. The below subroutine "un-hides" a file (if it is
hidden):
|
Well, that about wraps up this article. We examined the Attributes property of the File object and
how to use it to read (and modify) a file's various attributes through code. For more information on the
Attributes property, be sure to check out the technical
docs!
Happy Programming!



