{"id":106194,"date":"2022-01-25T07:00:00","date_gmt":"2022-01-25T15:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=106194"},"modified":"2022-01-25T06:59:49","modified_gmt":"2022-01-25T14:59:49","slug":"20220125-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20220125-00\/?p=106194","title":{"rendered":"I deleted a file from Explorer, but it came back when I refreshed, and I get Access Denied if I try to delete it again"},"content":{"rendered":"<p>A customer reported that if they go into Explorer and delete a file, the file disappears from the Explorer window, but if they refresh the window, the file comes back. If they try to delete the file again, they get an <i>Access Denied<\/i> error.<\/p>\n<p>What&#8217;s going on?<\/p>\n<p>The Windows model for file deletion is that <a href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20040607-00\/?p=38993\"> deleting a file doesn&#8217;t take effect until all open handles to the file are closed<\/a>. When you delete the file from Explorer, the file operation engine performs a <code>Delete\u00adFile<\/code> to delete the file, and the call says &#8220;Yup, the file is deleted. Everything is awesome.&#8221; But secretly, everything isn&#8217;t awesome <i>yet<\/i>.<\/p>\n<p>The file operation engine is told that the <code>Delete\u00adFile<\/code> was successful, so it sends out a notification that says, &#8220;In case anybody cares, I just deleted a file!&#8221; The Explorer window receives this notification and removes the file from the view.<\/p>\n<p>When you refresh the window, the Explorer window goes back and enumerates the contents of the directory, and hey look, the file is still there. So it shows back up.<\/p>\n<p>If you try to delete the file a second time, the call to <code>Delete\u00adFile<\/code> fails because the file has already been logically deleted. The file system is just waiting for everybody who was using the file to be done with it.<\/p>\n<p>The customer&#8217;s investigation was that the file is indeed still open. The had an application running that had the file on a work list, and to ensure that the work could be completed, the application keeps a handle open to those files until the work is completed (or canceled).<\/p>\n<p>The customer wanted to know if there was a way to make the file really be deleted when the user deletes it, so it doesn&#8217;t show up in the Explorer view, because their employees&#8217; workflow is to delete the file when they&#8217;ve finished with it, and having the file linger in the view makes it hard to keep track of what is left to be done.<\/p>\n<p>Well, the work isn&#8217;t actually done, because it&#8217;s still sitting on the application&#8217;s work list. They can adjust their workflow so they delete the file when the application completes the work item. Or find a way to delete the work item from the application&#8217;s work list. Or they could talk to the application vendor and ask if there&#8217;s an option to disable the &#8220;keep an open handle to the file&#8221; feature, even though it means that when the application goes to work on the file, the file may not be there any more. (Or it might be a different file entirely, just with a coincidentally identical name.)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The file is circling the drain, but it&#8217;s not gone yet.<\/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":[104],"class_list":["post-106194","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-tipssupport"],"acf":[],"blog_post_summary":"<p>The file is circling the drain, but it&#8217;s not gone yet.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/106194","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=106194"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/106194\/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=106194"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=106194"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=106194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}