{"id":20833,"date":"2008-09-19T10:00:00","date_gmt":"2008-09-19T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2008\/09\/19\/how-can-i-tell-that-a-directory-is-weird-and-should-be-excluded-from-the-user-interface\/"},"modified":"2008-09-19T10:00:00","modified_gmt":"2008-09-19T10:00:00","slug":"how-can-i-tell-that-a-directory-is-weird-and-should-be-excluded-from-the-user-interface","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20080919-00\/?p=20833","title":{"rendered":"How can I tell that a directory is weird and should be excluded from the user interface?"},"content":{"rendered":"<p><P>\n<!-- backref: recycle bin -->\nLast time<\/A>, we looked at a customer who wanted to know how to tell\nwhether a given folder was a Recycle Bin folder or not.\nWe answered the question as stated,\nbut made the mistake of not looking\nat the problem the customer was trying to solve.\n<\/P>\n<BLOCKQUOTE CLASS=\"q\">\nI need to know which folders are Recycle Bin folders so I can\nskip over them when searching the drive for content.\n<\/BLOCKQUOTE>\n<P>\nAh, the real question isn&#8217;t &#8220;How can I tell whether a directory\nis a Recycle Bin folder?&#8221; but rather\n&#8220;How can I tell whether a directory contains weird stuff that\nwe shouldn&#8217;t be showing to the user (of which Recycle Bin files\nare just one example)?&#8221;\n<\/P>\n<P>\nThe way to mark a folder as containing stuff that you shouldn&#8217;t\nbother the user with is to set both the <CODE>FILE_ATTRIBUTE_HIDDEN<\/CODE>\nand <CODE>FILE_ATTRIBUTE_SYSTEM<\/CODE> attributes.\nIn addition to Recycle Bin directories, this also prevents you\nfrom searching weird things like System Restore points.\n(Though for some reason it doesn&#8217;t stop you from searching\nTemporary Internet Files; I don&#8217;t know whether that is a bug or a feature.)\n<\/P>\n<P>\nTherefore, the answer to &#8220;How can I tell whether a directory\ncontains weird stuff that we shouldn&#8217;t be showing to the user?&#8221;\nis to test for the hidden and system attributes.\n<\/P>\n<PRE>\nBOOL IsWeirdDirectory(LPCTSTR pszDir)\n{\n  DWORD dwAttr = GetFileAttributes(pszDir);\n  return dwAttr != INVALID_FILE_ATTRIBUTES &amp;&amp;\n         ((dwAttr &amp; (FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))\n                 == (FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN));\n}\n<\/PRE><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last time, we looked at a customer who wanted to know how to tell whether a given folder was a Recycle Bin folder or not. We answered the question as stated, but made the mistake of not looking at the problem the customer was trying to solve. I need to know which folders are Recycle [&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-20833","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Last time, we looked at a customer who wanted to know how to tell whether a given folder was a Recycle Bin folder or not. We answered the question as stated, but made the mistake of not looking at the problem the customer was trying to solve. I need to know which folders are Recycle [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/20833","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=20833"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/20833\/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=20833"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=20833"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=20833"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}