How Unrar Handles the Archive Bit on Windows

This article explains how the UnRAR utility processes the Windows "Archive" file attribute during file extraction. It details how attributes are preserved in RAR archive headers, how UnRAR interacts with the Windows API to apply or clear the archive bit on newly extracted files, and which command-line switches alter this default behavior.

The Archive Attribute in Windows

In Windows file systems (NTFS, FAT32, and ReFS), the Archive bit (FILE_ATTRIBUTE_ARCHIVE, value 0x20) is a metadata flag used primarily by backup software. When any file is created or modified, the Windows kernel automatically sets this bit to indicate that the file has changed and needs to be backed up.

How RAR Stores File Attributes

When WinRAR or the RAR command-line tool creates an archive on Windows, it reads the file attributes via the Windows API and records them into the RAR file header. The standard DOS/Windows attribute flags—Read-Only (0x01), Hidden (0x02), System (0x04), and Archive (0x20)—are stored as part of the file metadata block inside the .rar container.

UnRAR Processing During Extraction

When UnRAR extracts a file on a Windows system, the processing of the archive bit occurs in distinct stages:

  1. File Creation: UnRAR creates the target file using the Win32 API function CreateFile(). By default, the Windows operating system automatically assigns the Archive attribute to any newly created file.
  2. Payload Writing: The decompressed data streams are written to the target file, and file handles are closed.
  3. Attribute Restoration: Once writing is complete, UnRAR reads the original attribute bitmask stored inside the RAR archive header.
  4. Explicit Application via API: UnRAR calls SetFileAttributesW() with the exact bitmask recorded during compression.

Because SetFileAttributesW() replaces the existing attribute flags rather than merging them, the final state of the archive bit depends entirely on the state it had when compressed:

  • If the original file had the Archive bit set, UnRAR explicitly sets it (or leaves it set).
  • If the original file had the Archive bit cleared (for instance, if a backup tool had already processed it), UnRAR strips the Archive bit from the newly created file, overriding the Windows default.

Overriding Attribute Handling with Switches

UnRAR provides command-line options to modify how file attributes are applied:

  • -ai (Ignore file attributes): Tells UnRAR not to restore the stored DOS/Windows attributes from the archive header. When this switch is used, the file retains the default attributes assigned by the Windows operating system at creation, meaning the Archive bit remains set, while Read-Only, Hidden, and System attributes from the archive are ignored.
  • -or (Automatically rename existing files): If a file already exists and is overwritten or renamed, the standard extraction process still concludes with an explicit attribute update matching the archive's header data.