O'Reilly logo

Applied Microsoft® .NET Framework Programming by Jeffrey Richter

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Bit Flags

Programmers frequently work with sets of bit flags. When you call the System.IO.File type’s GetAttributes method, it returns an instance of a FileAttributes type. A FileAttributes type is an instance of an Int32-based enumerated type, where each bit reflects a single attribute of the file. The FileAttributes type is defined in the FCL as follows:

[Flags, Serializable]
public enum FileAttributes {
   ReadOnly          = 0x0001,
   Hidden            = 0x0002,
   System            = 0x0004,
   Directory         = 0x0010,
   Archive           = 0x0020,
   Device            - 0x0040,
   Normal            = 0x0080,
   Temporary         = 0x0100,
   SparseFile        = 0x0200,
   ReparsePoint      = 0x0400,
   Compressed        = 0x0800,
   Offline           = 0x1000,
   NotContentIndexed = 0x2000,
   Encrypted         = 0x4000
}

To determine whether a file is hidden, you would execute code like this: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required