the File IO is based on the ActiveX technology. You create an ActiveX File object by calling ActiveXObject() with a single argument, Scripting.FileSystemObject:
myActiveXObject = new ActiveXObject("Scripting.FileSystemObject");
You can create a File object by using the ActiveX's GetFile() method:
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] = 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
returns 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 |
0 | A Normal file. No attributes set. |
1 | File is read only. Read/Write. |
2 | File is hidden. Read/Write. |
4 | File is a system file. Read/Write. |
8 | Disk drive volume label. Read only. |
16 | Folder in a directory. Read only. |
32 | File has changed since last backup. Read only. |
64 | A link or shortcat. Read only. |
128 | Disk drive volume label. |
Learn more about ActiveX controls in Column 55, OLE Automation in JavaScript.
People who read this tip also read these tips:
Look for similar tips by subject:
|