{"id":97365,"date":"2017-11-08T07:00:00","date_gmt":"2017-11-08T22:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/?p=97365"},"modified":"2019-03-13T01:20:05","modified_gmt":"2019-03-13T08:20:05","slug":"20171108-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20171108-00\/?p=97365","title":{"rendered":"How can I control which parts of the shell namespace the INamespaceWalk::Walk operation will walk into?"},"content":{"rendered":"<p>The <code>INamespace&shy;Walk::<\/code><code>Walk<\/code> method initiates a depth-first traversal of the shell namespace, subject to constraints controlled by the various parameters (such as maximum search depth). If you pass an object which implements the <code>INamespace&shy;Walk&shy;CB<\/code> interface, you can monitor the progress of the namespace walk and also influence how it proceeds. <\/p>\n<p>The <code>Enter&shy;Folder<\/code> method is called when the namespace walk finds an object in the shell namespace with the <code>SFGAO_<\/code><code>FOLDER<\/code> attribute. You can perform whatever actions you wish in response to this callout, and you can provide limited feedback to the namespace walk operation: <\/p>\n<ul>\n<li>Return <code>S_OK<\/code> to allow the namespace walk to     recurse into the folder.     The folder is eligible to be reported by     <code>INamespace&shy;Walk::<\/code><code>Get&shy;ID&shy;Array&shy;Result<\/code>.     <\/li>\n<li>Return <code>S_FALSE<\/code> to prevent the namespace walk from     recursing into the folder.     The folder is eligible to be reported by     <code>INamespace&shy;Walk::<\/code><code>Get&shy;ID&shy;Array&shy;Result<\/code>.     <\/li>\n<li>Return a COM error <code>HRESULT<\/code> to abandon the     namespace walk operation.     The error code you return will be the return value of the     <code>INamespace&shy;Walk::<\/code><code>Walk<\/code> method.     <\/li>\n<\/ul>\n<p>The <code>Found&shy;Item<\/code> method is called when the namespace walk finds an object in the shell namespace without the <code>SFGAO_<\/code><code>FOLDER<\/code> attribute. Again, you can perform whatever actions you wish in response to this callout, and you can provide limited feedback to the namespace walk operation: <\/p>\n<ul>\n<li>Return <code>S_OK<\/code> to allow the namespace walk to     continue.     The item will be reported by     <code>INamespace&shy;Walk::<\/code><code>Get&shy;ID&shy;Array&shy;Result<\/code>.     <\/li>\n<li>Return a COM error <code>HRESULT<\/code> to abandon the     namespace walk operation.     The error code you return will be the return value of the     <code>INamespace&shy;Walk::<\/code><code>Walk<\/code> method.     <\/li>\n<\/ul>\n<p>Note that &#8220;allow the namespace walk to recurse into the folder&#8221; and &#8220;eligible to be reported by <code>INamespace&shy;Walk::<\/code><code>Get&shy;ID&shy;Array&shy;Result<\/code>&#8221; are both conditional upon how the namespace walk is configured. For example, if recursing into the folder would exceed the recursion depth, then recursion won&#8217;t occur even if you say &#8220;Sure, go ahead&#8221; in your <code>Enter&shy;Folder<\/code> handler. <\/p>\n<p>The <code>Leave&shy;Folder<\/code> method is called when the namespace walk has finished enumerating the contents of a folder. It is the counterpart to <code>Enter&shy;Folder<\/code>. This is your chance to perform any cleanup or other actions. (For example, if you are counting the number of items in each folder, this tells you that the enumeration of a folder is complete, and you can save the totals to wherever you intend to save them.) The return value here does not affect the namespace walk. <\/p>\n<p>Let&#8217;s go with the table again: <\/p>\n<table BORDER=\"1\" CELLPADDING=\"3\" CLASS=\"cp3\" STYLE=\"border-collapse: collapse\">\n<tr>\n<th>Operation<\/th>\n<th><code>S_OK<\/code><\/th>\n<th><code>S_FALSE<\/code><\/th>\n<th>COM error<\/th>\n<\/tr>\n<tr>\n<td><code>Enter&shy;Folder<\/code><\/td>\n<td>\n<div>Allow recursion<br>Allow reporting<br>Continue<\/div>\n<\/td>\n<td>\n<div>Block recursion<br>Allow reporting<br>Continue<\/div>\n<\/td>\n<td>\n<div>Block recursion<br>Block reporting<br>Abandon<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>Found&shy;Item<\/code><\/td>\n<td>\n<div>Allow reporting<br>Continue<\/div>\n<\/td>\n<td>Not allowed<\/td>\n<td>\n<div>Block reporting<br>Abandon<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td><code>Leave&shy;Folder<\/code><\/td>\n<td>Continue<\/td>\n<td>Not allowed<\/td>\n<td>Continue<\/td>\n<\/tr>\n<\/table>\n<p>The boxes marked &#8220;Not allowed&#8221; indicate that returning <code>S_FALSE<\/code> is not allowed for those methods. <\/p>\n<p><b>Exercise 1<\/b>: A customer had the following question. Maybe you can answer it. <\/p>\n<blockquote CLASS=\"q\"><p>We are using <code>INamespace&shy;Walk::<\/code><code>Walk<\/code>, and we&#8217;re passing the <code>NSWF_<\/code><code>TRAVERSE_<\/code><code>STREAM_<\/code><code>JUNCTIONS<\/code> flag so that it recurses into CAB folders, but it&#8217;s also recursing into ZIP folders. How can we stop it from recursing into ZIP folders? <\/p><\/blockquote>\n<p><b>Exercise 2<\/b>: Suppose you want to process at most the first 100 files. How would you stop the namespace walk operation after 100 files have been processed? <\/p>\n","protected":false},"excerpt":{"rendered":"<p>You can ask it to skip the folder, or you can tell it to give up entirely.<\/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-97365","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>You can ask it to skip the folder, or you can tell it to give up entirely.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/97365","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=97365"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/97365\/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=97365"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=97365"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=97365"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}