File Attributes
File attributes are metadata flags that describe the state and behavior of files and directories in the Windows operating system. They are stored in the file system and can be read or modified programmatically.
| Attribute | Value (Hex) | Description |
|---|---|---|
| ReadOnly | 0x00000001 | Prevents write operations on the file. |
| Hidden | 0x00000002 | File is not visible in standard directory listings. |
| System | 0x00000004 | File is used by the operating system. |
| Directory | 0x00000010 | Entry is a directory. |
| Archive | 0x00000020 | File has changed since the last backup. |
| Device | 0x00000040 | Reserved for system use. |
| Normal | 0x00000080 | No other attributes are set. |
| Temporary | 0x00000100 | File is temporary and may be deleted soon. |
| SparseFile | 0x00000200 | File is a sparse file. |
| ReparsePoint | 0x00000400 | File contains a reparse point. |
| Compressed | 0x00000800 | File is compressed. |
| Offline | 0x00001000 | Data is not immediately available. |
| NotContentIndexed | 0x00002000 | File is excluded from indexing. |
| Encrypted | 0x00004000 | File is encrypted. |
| IntegrityStream | 0x00008000 | File has integrity metadata. |
| Virtual | 0x00010000 | File is a virtual (non-disk) file. |
| NoScrubData | 0x00020000 | File is exempt from data scrubbing. |
Getting File Attributes in C#
using System;
using System.IO;
class Program
{
static void Main()
{
string path = @"C:\Temp\example.txt";
FileAttributes attrs = File.GetAttributes(path);
Console.WriteLine($""Attributes for {path}: {attrs}"");
if ((attrs & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
{
Console.WriteLine(""File is read‑only"");
}
}
}
Getting File Attributes in C++ (WinAPI)
For a complete reference, see the File Attribute Functions page.