What is the programmatic equivalent to unchecking the box to prevent a file from having its contents indexed?

Raymond Chen

A customer wanted to know how they could write a program that automatically checked and unchecked the box that appears on a file’s property sheet on the General tab, clicking the Advanced button, and then checking or unchecking the item whose name keeps changing:

  • On Windows 7, it’s called Allow this file to have contents indexed in addition to file properties.
  • On Windows Vista, it’s called Index this file for faster searching.
  • On Windows 2000 and Windows XP, it’s called For fast searching, allow Indexing Service to index this folder.

The checkbox maps to the file attribute formally known as FILE_ATTRIBUTE_NOT_CONTENT_INDEXED, and informally known as FANCI (pronounced like the word fancy). Checking the box clears the attribute, and unchecking the box sets the attribute. The customer liaison replied, “Thanks for your assistance. The customer was able to use the System.IO.File.Set­Attributes method with the values in the System.IO.File­Attributes enumeration to manipulate the indexing attribute. The customer has a follow-up question, however: ‘I need this change to be applied recursively to all files in a entire directory subtree. Is there a single series of Visual Basic commands that will accomplish this, or do I need to write a loop by hand?’” This question kind of ran off topic for the product team and fell more in line with Developer Support. I suggested that the follow-up question be redirected to the Visual Basic support team. For me, it was interesting that (1) the customer liaison was himself not aware enough to realize that the question had changed audiences, and (2) the customer was so helpless that they couldn’t look for the answer themselves.

Bonus chatter: The file system itself pays no attention to the FANCI bit. It’s just a signal to any program that does file content indexing that this particular file should be skipped. Whether any particular search index program respects the flag is something you need to take up with the vendor of that search index program. (As far as I’m aware, all Microsoft search indexes should honor the flag.)

0 comments

Discussion is closed.

Feedback usabilla icon