Folder.Attributes (Property)

The file system attributes of a folder.

Availability:

JScript - 3.0
Internet Explorer - 4.0
Property/method value type:Number primitive
JavaScript syntax:IEmyFolder.Attributes

Folders have attributes that control how they can be used and accessed. This property contains the attributes for the folder encapsulated by this object.

The attributes can be manipulated in a similar way to those belonging to the File object.

This property manages the attributes as a bit-mask with individual bits controlling different attributes. The bits can be accessed individually using the integer value corresponding to a power of 2. The table lists the integers that represent each different attribute.

You can use Bitwise OR expressions to merge them or accomplish the same with integer additions.

ValueAttribute
0No special attributes - normal folder.
1Read-only access.
2Hidden folder.
4Indicates a system folder.
8Refers to drive volume label and cannot be altered.
16Refers to a directory and cannot be changed.
32Folder has changed and needs to be backed up again.
64Folder object represents a shortcut and not a real folder.
128Folder is compressed.

You cannot alter the settings of bits 8, 16, 64 and 128 as these affect the structure of a file. That is to say, you cannot change a folder into a file or disk volume.

You should read the current attributes setting and then modify it to write it back. The example illustrates some simple functions that encapsulate this conveniently.

Where the bit needs to be set, a simple bitwise OR with a single bit value is accomplished in a single line. To clear a bit, we could use a bitwise AND having the corresponding bit clear. In these examples a different technique is used for illustration where the bit is set regardless of its previous state and is then cleared using a subtraction. That saves the computation of a complex bit mask. An intermediate temporary variable is used to avoid signalling the operating system unnecessarily with modification requests.

There are other alternative ways to accomplish this and you could write some generic functions to examine, set or clear a bit in a bit-mask and then call them from each of these wrappers indicating the bit you want to operate on.

Example code:

   // Examine the read/write flag
   function isReadOnly(aFolder)
   {
       return Boolean(aFolder.Attributes & 1);
   }
   // Set the folder read only
   function setReadOnly(aFolder)
   {
      aFolder.Attributes |= 1;
   }
   // Set the folder read/write
   function setWriteOnly(aFolder)
   {
      var myAttributes = aFolder.Attributes |= 1;
      aFolder.Attributes = myAttributes - 1;
   }
   // ----------------------------------------------------
   // Examine the hidden flag
   function isHidden(aFolder)
   {
      return Boolean(aFolder.Attributes & 2);
   }
   // Hide the folder
   function setHidden(aFolder)
   {
      aFolder.Attributes |= 2;
   }
   // Reveal the folder
   function setVisible(aFolder)
   {
      var myAttributes = aFolder.Attributes |= 2;
      aFolder.Attributes = myAttributes - 2;
   }
   // ----------------------------------------------------
   // Examine the system flag
   function isSystemFolder(aFolder)
   {
      return Boolean(aFolder.Attributes & 4);
   }
   // Set file to be a system folder
   function setSystem(aFolder)
   {
      aFolder.Attributes |= 4;
   }
   // Set file to be a non system folder
   function setPublic(aFolder)
   {
      var myAttributes = aFolder.Attributes |= 4;
      aFolder.Attributes = myAttributes - 4;
   }
   // ----------------------------------------------------
   // Examine the drive volume flag
   function isDriveVolume(aFolder)
   {
      return Boolean(aFolder.Attributes & 8);
   }
   // ----------------------------------------------------
   // Examine the folder flag
   function isFolder(aFolder)
   {
      return Boolean(aFolder.Attributes & 16);
   }
   // ----------------------------------------------------
   // Examine the backup flag
   function needsBackup(aFolder)
   {
      return Boolean(aFolder.Attributes & 32);
   }
   // Set backup required
   function setBackup(aFolder)
   {
      aFolder.Attributes |= 32;
   }
   // Clear backup
   function clearBackup(aFolder)
   {
      var myAttributes = aFolder.Attributes |= 32;
      aFolder.Attributes = myAttributes - 32;
   }
   // ----------------------------------------------------
   // Examine the shortcut flag
   function isShortCut(aFolder)
   {
      return Boolean(aFolder.Attributes & 64);
   }
   // ----------------------------------------------------
   // Examine the compressed flag
   function isCompressed(aFolder)
   {
      return Boolean(aFolder.Attributes & 128);
   }

See also:File.Attributes