{"id":1493,"date":"2014-03-17T07:00:00","date_gmt":"2014-03-17T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2014\/03\/17\/how-do-i-show-the-contents-of-a-directory-while-respecting-the-users-preferences-for-hidden-and-super-hidden-files-as-well-as-the-users-language-preferences\/"},"modified":"2014-03-17T07:00:00","modified_gmt":"2014-03-17T07:00:00","slug":"how-do-i-show-the-contents-of-a-directory-while-respecting-the-users-preferences-for-hidden-and-super-hidden-files-as-well-as-the-users-language-preferences","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20140317-00\/?p=1493","title":{"rendered":"How do I show the contents of a directory while respecting the user&#039;s preferences for hidden and super-hidden files as well as the user&#039;s language preferences?"},"content":{"rendered":"<p>\nA customer was writing a program in (and this is what they said)\n&#8220;32 bit C++ .Net 4.0&#8221;\nwhich displayed the contents of\na directory,\nand they wanted to filter out items such as hidden files\nand protected operating system files\n(also known as <i>super-hidden<\/i> files)\nbased on the user&#8217;s current Explorer preferences.\nFurthermore, they wanted to show localized folder names,\nsuch as <i>Usarios<\/i> instead of <i>Users<\/i>,\nagain, the same way Explorer does.\nThey are currently using\n<code>Directory.Get&shy;Directories()<\/code>.\n<\/p>\n<p>\nThe way to do this is to use\n<code>IShell&shy;Folder::Enum&shy;Object<\/code>,\nthe same way Explorer does.\nDon&#8217;t pass\n<code>SHCONTF_INCLUDE&shy;HIDDEN<\/code>\nor\n<code>SHCONTF_INCLUDE&shy;SUPER&shy;HIDDEN<\/code>,\nand you will get the default enumeration that filters out\nhidden items based on the user&#8217;s preferences.\n(You pass the flag to force the items to be included,\noverriding the user&#8217;s preferences.)\nand the names of the items that come out of the enumeration\nwill be the localized names.\nYou can ask for the parsing name to get the physical file name.\n<\/p>\n<pre>\n#define UNICODE\n#define <a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2004\/02\/12\/71851.aspx\">_UNICODE<\/a>\n#define STRICT\n#define <a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2013\/01\/24\/10387757.aspx\">STRICT_TYPED_ITEMIDS<\/a>\n#include &lt;windows.h&gt;\n#include &lt;shlobj.h&gt;\n#include &lt;atlbase.h&gt;\n#include &lt;atlalloc.h&gt;\nint __cdecl wmain(int argc, wchar_t **argv)\n{\n <a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2004\/05\/20\/135841.aspx\">CCoInitialize<\/a> init;\n if (argc &lt; 2) return 0;\n CComHeapPtr&lt;ITEMIDLIST_ABSOLUTE&gt; sppidl;\n CComPtr&lt;IShellFolder&gt; spsf;\n CComPtr&lt;IEnumIDList&gt; speidl;\n if (FAILED(SHParseDisplayName(argv[1], nullptr,\n                               &amp;sppidl, 0, nullptr)) ||\n     FAILED(SHBindToObject(nullptr, sppidl,\n                           nullptr, IID_PPV_ARGS(&amp;spsf))) ||\n     FAILED(spsf-&gt;EnumObjects(nullptr,\n               SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &amp;speidl)) ||\n     speidl == nullptr) return 0;\n for (CComHeapPtr&lt;ITEMID_CHILD&gt; sppidlItem;\n      speidl-&gt;Next(1, &amp;sppidlItem, nullptr) == S_OK;\n      sppidlItem.Free()) {\n  <a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2011\/08\/30\/10202076.aspx\">PrintDisplayName<\/a>(spsf, sppidlItem, SHGDN_NORMAL, L\"Display Name\");\n  PrintDisplayName(spsf, sppidlItem, SHGDN_FORPARSING, L\"For Parsing\");\n  wprintf(L\"\\n\");\n }\n}\n<\/pre>\n<p>\nThe program takes a fully-qualified path on the command line\nand displays its contents (both in localized display name and\nin raw file system paths) while respecting the user&#8217;s preferences\nfor hidden and super-hidden files.\n<\/p>\n<p>\nIt appears that the customer is writing their program in C#,\ndespite their claim that they were using C++\n(or maybe they meant MC++ or C++\/CLI).\nIn that case, they can use the\n<i>Windows&nbsp;7 API CodePack for Microsoft&reg; .NET Framework<\/i>\n(gotta love that\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/jonathanh\/archive\/2005\/08\/05\/what-s-the-longest-microsoft-product-name.aspx\">\ncatchy name<\/a>).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A customer was writing a program in (and this is what they said) &#8220;32 bit C++ .Net 4.0&#8221; which displayed the contents of a directory, and they wanted to filter out items such as hidden files and protected operating system files (also known as super-hidden files) based on the user&#8217;s current Explorer preferences. Furthermore, they [&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-1493","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>A customer was writing a program in (and this is what they said) &#8220;32 bit C++ .Net 4.0&#8221; which displayed the contents of a directory, and they wanted to filter out items such as hidden files and protected operating system files (also known as super-hidden files) based on the user&#8217;s current Explorer preferences. Furthermore, they [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/1493","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=1493"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/1493\/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=1493"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=1493"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=1493"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}