spacer
Yehuda Shiran October 22, 2000
Setting and Getting the File Attributes
Tips: October 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

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 ValueDescription
0A Normal file. No attributes set.
1File is read only. Read/Write.
2File is hidden. Read/Write.
4File is a system file. Read/Write.
8Disk drive volume label. Read only.
16Folder in a directory. Read only.
32File has changed since last backup. Read only.
64A link or shortcat. Read only.
128Disk 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:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint