title: Can't delete a folder on Windows 7 with a trailing space
body: <p><strong>Issue:</strong> I have a Windows&nbsp;7 sub-directory which I can't delete.</p>
  
  <p>While I know others here, and many more elsewhere on the Internet have asked about this general class of Windows&nbsp;7 file system problem, my question here specifically relates to the specific class of un-deletable files on Windows&nbsp;7 which have <strong>a trailing space in the directory name.</strong></p>
  
  <p>Is there a better tool to inspect and/or edit my filesystem (in hex if need be)?</p>
  
  <hr>
  
  <p><strong>OS:</strong> I'm running x64 professional and it's fully updated.</p>
  
  <p><strong>What has been tried:</strong> I have read many web pages on this subject and tried many potential solutions. I have been studding the problem most recently using PowerShell which seems to be fully capable of dealing with system internals. At this point I am looking for something like a hex editor for the filesystem.</p>
  
  <p><strong>What it's not caused by:</strong></p>
  
  <ul>
  <li>a long file-name, or</li>
  <li>by being located in a lengthy path,</li>
  </ul>
  
  <p><strong>What it's not fixed by:</strong></p>
  
  <ul>
  <li>Renaming using the old DOS file naming scheme</li>
  <li>Running <a href="http://en.wikipedia.org/wiki/CHKDSK" rel="noreferrer">CHKDSK</a> of the entire file system</li>
  <li>Shutting down all other programs which might be accessing it</li>
  <li>Disabling virus software</li>
  <li>Using the Delinvfile.exe 4.5 utility. Note: Delinvfile says that it can't fix, "Files and Folders with a shortname that contains invalid characters. These include the characters [which are disallowed in file-names]:</li>
  </ul>
  
  <blockquote>
  <pre><code>&lt;  -  Less than symbol
  &gt;  -  Greater than symbol
  :  -  Colon
  "  -  Quotation Mark
  /  -  Forward Slash
  |  -  Vertical Bar
  ?  -  Question mark
  *  -  Asterisk
  </code></pre>
  </blockquote>
  
  <p><strong>What caused it?</strong> In my case the un-deletable sub-directory was created some months ago with a custom <a href="http://en.wikipedia.org/wiki/PHP" rel="noreferrer">PHP</a> program that I use for source tree backups. It appears to have either a space or other bad character in the name, but I can't be sure. It is visible in a file directory, but unavailable to delete, rename, rmdir, etc.</p>
  
  <p><strong>Investigation:</strong> I can move it around on my file system and have placed it inside a sub-directory called, 'holds bad subdir' on C:.</p>
  
  <p>Here you can see it <a href="http://www.microsoft.com/powershell" rel="noreferrer">with PowerShell</a>. First I show it with a <a href="http://technet.microsoft.com/en-us/library/hh849800.aspx" rel="noreferrer">Get-ChildItem</a> (which is the same as the alias 'dir'):</p>
  
  <pre><code>PS C:\holds bad subdir&gt; Get-ChildItem
  
  
      Directory: C:\holds bad subdir
  
  
  Mode                LastWriteTime     Length Name
  ----                -------------     ------ ----
  d----        1/9/2014   3:01   AM            20120530-04
  </code></pre>
  
  <p>If I try to delete it in a cmd window by typing 'del "2' + tab, it completes the file name expansion as follows: del "20120530-04 ", showing that there is a space at the end of the directory name. When I execute this command the result is:</p>
  
  <blockquote>
    <p>Could Not Find C:\holds bad subdir\20120530-04</p>
  </blockquote>
  
  <p>If I try to delete it with del 2*, the system returns as if though it had deleted it, but does not.</p>
  
  <p>If I issue this same command in PowerShell, and also with the <code>Force</code> option, it reports, "An object at the specified path C:\holds bad subdir\20120530-04 does not exist.", as follows:</p>
  
  <pre><code>PS C:\holds bad subdir&gt; Remove-Item 2* -Force  Remove-Item : An object at the specified path C:\holds bad subdir\20120530-04  does not exist.At line:1 char:1
  + Remove-Item 2* -Force
  + ~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : InvalidArgument: (:) [Remove-Item], PSArgumentException
      + FullyQualifiedErrorId : Argument,Microsoft.PowerShell.Commands.RemoveItemCommand
  </code></pre>
  
  <p>This is sort of strange because the directory can clearly see it, but any methods apparently either can't see it or can't be applied to it.</p>
  
  <p>I can also view the un-deletable sub-directory in <a href="http://en.wikipedia.org/wiki/Windows_Explorer" rel="noreferrer">Windows&nbsp;Explorer</a>. When I browse into it, it says, "this folder is empty". And if I try to delete it there I get:</p>
  
  <p><img src="https://i.stack.imgur.com/4pKM5.png" alt="Enter image description here"></p>
  
  <p>Also if I view the <em>properties</em> of this folder I can see that the name is "20120530-04 ", that is, with an extra space at the end.</p>
  
  <p><img src="https://i.stack.imgur.com/DT1by.png" alt="Enter image description here"></p>
  
  <p>Also interestingly, the Security tab reports "(X) The requested security information is either unavailable or can't be displayed."</p>
  
  <p>And it's not Read-only, nor Hidden.</p>
  
  <hr>
  
  <p><strong>Scope of issue:</strong> Now, this is not a big problem, it is easy to bury this sub-directory inside an out-of-the-way sub-directory and just not worry about it.</p>
  
  <p>But for me this has turned into an intellectual challenge and partly a way to learn more about the guts of Windows&nbsp;7. I guess I am amazed that such a bug in Windows could exist at such a low level, and with so many systems installed in the world. It's hard at this point to know if this is a Windows bug, bad data (that a bug let in), or just bad data.</p>