October 22, 2000 - Setting and Getting the File Attributes
October 22, 2000|
Setting and Getting the File Attributes
Tips: October 2000
Yehuda Shiran, Ph.D.
ActiveXObject()with a single argument,
myActiveXObject = new ActiveXObject("Scripting.FileSystemObject");
You can create a File object by using the ActiveX's
file = myActiveXObject.GetFile("c:\\Autoexec.bat");
The File object supports various properties and methods, including the
attributes property. The
attributes property is an 8-bit bit property: every bit denotes a different file characteristic. To set or get a bit, you need to know how to compute powers of 2, up to and including 128. You set an attribute by setting its proper bit. To set the read-only characteristic, for example, you need to set the second bit:
file.attributes = 1;
You can set the bit by a either a unit value or by a true value. To get a bit value, you need to use the Bit-And operation. The Bit-And operation returns
true when the corresponding bit is set, and
false otherwise. For example:
file.attributes & 32
true if the sixth bit is set,
false otherwise. Here are all the attributes and their bit value. The Description column indicates the attribute values when the corresponding bit is set:
Bit Value Description
A Normal file. No attributes set.
File is read only. Read/Write.
File is hidden. Read/Write.
File is a system file. Read/Write.
Disk drive volume label. Read only.
Folder in a directory. Read only.
File has changed since last backup. Read only.
A link or shortcat. Read only.
Disk drive volume label.