Dave
Dave

Reputation: 8461

File attribute flags is controlled by code or OS?

I am learning about the file attribute enum and have a two questions which I can't find a concrete answer to (although I have my own opinion).

My application checks to see if the Archive flag has been set or not. During my testing, I create a .txt file on my desktop, and removed the flag to archive. I then opened the file, added a line of text and saved the file. The attribute Archive was re-set. This is logical and desirable.

My first question is, what is setting the flag, the program or the OS?

My second question is, should I ever be setting the flags or for the most part can I rely on the OS (assuming that the OS is the thing which sets the flags).

Upvotes: 2

Views: 451

Answers (2)

Martin Liversage
Martin Liversage

Reputation: 106826

You can control the archive file attribute flag using the ATTRIB command line or the underlying Windows API (e.g. allowing "your code" full control of the flag). However, when a file is modified the archive flag is set. That is not something you have to do in your application or code. The expected usage scenario is this:

  • The operating system will set the flag when a file is created or modified

  • The backup application (e.g. "your code") will reset the flag when a file has been backed up

However, relying on the archive flag for backup can be problematic because multiple independent backup applications may be using the flag.

Upvotes: 2

BLoB
BLoB

Reputation: 9725

If the file has been 'touched' since the last backup DOS sets this archive bit.

e.g. when a file with a clear archive bit is moved from one place on a file system to another, the archive bit reverts to being set.

Upvotes: 1

Related Questions