{"id":44393,"date":"2015-03-25T07:00:00","date_gmt":"2015-03-25T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2015\/03\/25\/whats-the-difference-between-pathissystemfolder-and-protected-operating-system-files\/"},"modified":"2015-03-25T07:00:00","modified_gmt":"2015-03-25T07:00:00","slug":"whats-the-difference-between-pathissystemfolder-and-protected-operating-system-files","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20150325-00\/?p=44393","title":{"rendered":"What&#039;s the difference between PathIsSystemFolder and Protected Operating System Files?"},"content":{"rendered":"<p><a href=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2008\/09\/19\/8957958.aspx\"> The way to detect weird directories that should be excluded from the user interface<\/a> is to check for the <code>FILE_ATTRIBUTE_HIDDEN<\/code> and <code>FILE_ATTRIBUTE_SYSTEM<\/code> attributes being set simultaneously. This is the mechanism used <a href=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2005\/04\/19\/409620.aspx\"> when you uncheck <i>Hide protected operating system files<\/i> in the Folder Options dialog<\/a>. (Programmatically, you detect whether the user wants to see protected operating system files by checking the <code>fShow&shy;Super&shy;Hidden<\/code> member of the <code>SHELL&shy;STATE<\/code> structure.)\n Michael Dunn suggested <a href=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2008\/09\/19\/8957958.aspx#8959388\"> using <code>Path&shy;Is&shy;System&shy;Folder<\/code> to detect these special directories<\/a>, but that is not quite right.\n <code>Path&shy;Is&shy;System&shy;Folder<\/code> is for marking a directory as &#8220;This directory has a nondefault UI behavior attached to it. Please consult the <code>desktop.ini<\/code> file for more information.&#8221; You do this when your directory is, say, the root of a namespace extension, or it has been subjected to folder customization. Windows uses it to indicate that the directory has a localized name, as well as other funky internal state.\n There are two ways to mark a folder as having nondefault UI. One is to set the <code>FILE_ATTRIBUTE_READ&shy;ONLY<\/code> attribute, and the other is to set the <code>FILE_ATTRIBUTE_SYSTEM<\/code> attribute.\n Either one works, and <code>Path&shy;Is&shy;System&shy;Folder<\/code> checks for both, returning a nonzero value if either attribute is set.\n In its default configuration, Windows <a href=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2003\/09\/30\/55100.aspx\"> uses the read-only flag to mark folders with nondefault UI<\/a>. However, some applications mistakenly believe that if a directory is marked read-only, then files within the directory cannot be modified. As a result, these applications refuse to let you save your documents onto the desktop, for example. To work around this, you can use the <code>Use&shy;System&shy;For&shy;System&shy;Folders<\/code> to tell Windows to use the <code>FILE_ATTRIBUTE_SYSTEM<\/code> attribute instead. Of course, if you do that, you will run into problems with applications which mistakenly believe that if a directory is marked system, then the directory is inaccessible. So you get to pick your poison.\n Programmers who wish to mark a folder as having nondefault UI should use the <code>Path&shy;Make&shy;System&shy;Folder<\/code> function to set the appropriate attribute. That function consults the system policy and sets the attribute that the policy indicates should be used to mark folders with nondefault UI.<\/p>\n<p> Going back to the original question, then: The difference between <code>Path&shy;Is&shy;System&shy;Folder<\/code> and checking for folders that are marked hidden+system is that they check different things and have different purposes. <\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"3\" style=\"border-collapse: collapse\">\n<tr>\n<th>Function<\/th>\n<th>Test<\/th>\n<\/tr>\n<tr>\n<td><code>Path&shy;Is&shy;System&shy;Folder<\/code><\/td>\n<td>ReadOnly or System<\/td>\n<\/tr>\n<tr>\n<td>path is protected operating system folder<\/td>\n<td>Hidden and System<\/td>\n<\/tr>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>The way to detect weird directories that should be excluded from the user interface is to check for the FILE_ATTRIBUTE_HIDDEN and FILE_ATTRIBUTE_SYSTEM attributes being set simultaneously. This is the mechanism used when you uncheck Hide protected operating system files in the Folder Options dialog. (Programmatically, you detect whether the user wants to see protected operating [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-44393","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>The way to detect weird directories that should be excluded from the user interface is to check for the FILE_ATTRIBUTE_HIDDEN and FILE_ATTRIBUTE_SYSTEM attributes being set simultaneously. This is the mechanism used when you uncheck Hide protected operating system files in the Folder Options dialog. (Programmatically, you detect whether the user wants to see protected operating [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/44393","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=44393"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/44393\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=44393"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=44393"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=44393"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}