{"id":99225,"date":"2018-07-12T07:00:00","date_gmt":"2018-07-12T21:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/?p=99225"},"modified":"2019-03-13T00:40:19","modified_gmt":"2019-03-13T07:40:19","slug":"20180712-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20180712-00\/?p=99225\/","title":{"rendered":"Why does a non-recursive <CODE>Read&shy;Directory&shy;ChangesW<\/CODE> still report files created inside subdirectories?"},"content":{"rendered":"<p>A customer used the <code>Read&shy;Directory&shy;ChangesW<\/code> function to monitor a directory for changes, asking for notifications only for changes directly in the directory being monitored (<code>bWatchSubtree = false<\/code>). But they found that the <code>Read&shy;Directory&shy;ChangesW<\/code> function reported a change even when they created a file in a subdirectory, rather than in the directory being monitored. <\/p>\n<p>For example, if they asked to monitor the directory <code>C:\\dir1<\/code>, and a file was created at <code>C:\\dir1\\dir2\\file<\/code>, the <code>Read&shy;Directory&shy;ChangesW<\/code> function reported a change, even though the file was created in a subdirectory, and the request was for a non-recursive monitor. <\/p>\n<p>What gives? <\/p>\n<p>We saw <a HREF=\"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/20110812-00\/?p=9913\">some time ago<\/a> that the purpose of the <code>Read&shy;Directory&shy;ChangesW<\/code> function is to allow you to maintain a local copy of the contents of a directory: The idea is that you make an initial pass over the directory with <code>Find&shy;First&shy;File<\/code>\/<code>Find&shy;Next&shy;File<\/code>, and then you use the notifications from the <code>Read&shy;Directory&shy;ChangesW<\/code> function to make incremental updates to your local copy. <\/p>\n<p>And what happened here is that the contents of an enumeration of the <code>C:\\dir1<\/code> directory did in fact change. What changed is the last-modified date on <code>C:\\dir1\\dir2<\/code>! <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Because they do affect the top-level directory.<\/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-99225","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Because they do affect the top-level directory.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/99225","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=99225"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/99225\/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=99225"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=99225"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=99225"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}