Search code examples
c#.netwindowsindexingfile-attributes

Access the Windows context indexing file attribue using dotnet


How can I programmatically read and write the file and folder attribute which is set by the Windows "Allow files on this drive to have contents indexed in addition to file properties" dialog?


Solution

  • Like this apparently:

    // 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));