所有文件都有 FILE_ATTRIBUTE_ARCHIVE 属性

All files has FILE_ATTRIBUTE_ARCHIVE attribute

我正在开发一个程序,该程序应该从 std::vector 中的所选目录中检索所有文件的属性。

此代码显示了我如何获取文件属性:

DWORD attr_flags = GetFileAttributes(file_path);

if (attr_flags == INVALID_FILE_ATTRIBUTES) {
  std::cout << "Invalid file attributes." << std::endl;
  return;
}

代码会像这样解析检索到的标志:

if (attr_flags & FILE_ATTRIBUTE_ARCHIVE) {
  attrs.push_back(defines::Attributes::kArchive);
  attr_flags &= ~FILE_ATTRIBUTE_ARCHIVE;
}

if (attr_flags & FILE_ATTRIBUTE_COMPRESSED) {
  attrs.push_back(defines::Attributes::kCompressed);
  attr_flags &= ~FILE_ATTRIBUTE_COMPRESSED;
}

/* etc... */

所以,毕竟我正在将结果打印到控制台并得到这个:

谁能告诉我,为什么所有文件(甚至存档)都有存档属性?

P.S: MSDN 告诉

FILE_ATTRIBUTE_ARCHIVE  32 (0x20)

作为存档文件或目录的文件或目录。应用程序通常使用此属性来标记要备份或删除的文件。

"archive" 属性并不意味着 "this file is an archive"(如 ZIP 或 7Z 文件)。相反,它 typically means "this file needs to be backed up":

On Windows and OS/2, when a file is created or modified, the archive bit is set, and when the file has been backed up, the archive bit is cleared. Thus, the meaning of the archive bit is: this file is due for archiving, or: this file has not been archived.

An incremental backup task may use the archive bit to distinguish which files have already been backed up, and select only the new or modified files for backup.

我认为它在实践中不再被广泛使用(如果曾经使用过的话)。