{"id":223,"date":"2010-10-15T13:40:20","date_gmt":"2010-10-15T12:40:20","guid":{"rendered":"http:\/\/www.greyhathacker.net\/?p=223"},"modified":"2013-03-20T17:41:45","modified_gmt":"2013-03-20T16:41:45","slug":"unable-to-delete-folder-with-trailing-space","status":"publish","type":"post","link":"https:\/\/www.greyhathacker.net\/?p=223","title":{"rendered":"Unable to delete folder with trailing space"},"content":{"rendered":"<p>There are a number of possibilities as to why folders cannot be deleted but this one I came across recently got my attention. While decompressing a zip file it created its extracted folder but when I came to remove the folder it came up with the error &#8220;Cannot delete file: Cannot read from the source file or disk&#8221;. After investigating I realised that it had a trailing space at the end of the folder. Now I knew what was causing the removal to fail but how to get rid of it?<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" alt=\"\" src=\"\/images\/trailspace.jpg\" width=\"521\" height=\"329\" \/><\/p>\n<p>Well there are a few ways on how to remove folders with trailing spaces:<\/p>\n<p>1. Using the &#8220;\\\\?\\&#8221; syntax<br \/>\n2. Using 8.3 short filename format (if folder is more than 8 characters)<\/p>\n<p>Below is an example code which creates a folder called &#8220;testfolder&#8221; in C:\\TEMP with a trailing space. Note that after the space \\\\ is required for it to create the space after the folder. Once compiled and run it will create the testfolder, pause for 5 seconds and then remove it. The trailing space can be more than just one space character.<\/p>\n<p>#include &lt;stdio.h&gt;<br \/>\n#include &lt;windows.h&gt;<\/p>\n<p>int main()<br \/>\n{<br \/>\n\u00a0\u00a0\u00a0 CreateDirectory(&#8220;C:\\\\TEMP\\\\testfolder \\\\&#8221;, NULL);<br \/>\n\u00a0\u00a0\u00a0 Sleep(5000);<br \/>\n\u00a0\u00a0\u00a0 RemoveDirectory(&#8220;C:\\\\TEMP\\\\testfolder \\\\&#8221;);<br \/>\n\u00a0\u00a0\u00a0 return 0;<br \/>\n}<\/p>\n<p>Examples on how to delete trailing space folders from the console.<\/p>\n<p>C:\\&gt;rd c:\\temp\\testfo~1<br \/>\nC:\\&gt;rd &#8220;\\\\?\\c:\\temp\\testfolder &#8221;<\/p>\n<p>Reference:<\/p>\n<p><a href=\"http:\/\/support.microsoft.com\/kb\/320081\" target=\"_blank\">http:\/\/support.microsoft.com\/kb\/320081<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are a number of possibilities as to why folders cannot be deleted but this one I came across recently got my attention. While decompressing a zip file it created its extracted folder but when I came to remove the folder it came up with the error &#8220;Cannot delete file: Cannot read from the source [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,8],"tags":[23],"class_list":["post-223","post","type-post","status-publish","format-standard","hentry","category-all","category-bugs","tag-trailing"],"_links":{"self":[{"href":"https:\/\/www.greyhathacker.net\/index.php?rest_route=\/wp\/v2\/posts\/223","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.greyhathacker.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.greyhathacker.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.greyhathacker.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.greyhathacker.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=223"}],"version-history":[{"count":12,"href":"https:\/\/www.greyhathacker.net\/index.php?rest_route=\/wp\/v2\/posts\/223\/revisions"}],"predecessor-version":[{"id":687,"href":"https:\/\/www.greyhathacker.net\/index.php?rest_route=\/wp\/v2\/posts\/223\/revisions\/687"}],"wp:attachment":[{"href":"https:\/\/www.greyhathacker.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=223"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.greyhathacker.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=223"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.greyhathacker.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}