使用 dotnet 访问 Windows 上下文索引文件属性

Access the Windows context indexing file attribue using dotnet

如何以编程方式读取和写入由 Windows "Allow files on this drive to have contents indexed in addition to file properties" 对话框设置的文件和文件夹属性?

显然是这样的:

// read
var isContentIndexed = ((attributes & FileAttributes.NotContentIndexed) != FileAttributes.NotContentIndexed);

// set
File.SetAttributes(path, (File.GetAttributes(path) | FileAttributes.NotContentIndexed));

// remove
File.SetAttributes(path, (File.GetAttributes(path) & ~FileAttributes.NotContentIndexed));