Windows – How to delete a file that Windows says doesn’t exist

ntfswindows

This is a very similar problem to this QA ( How can I delete a file that "Does not exist" ), except I'm on an entirely Windows computer, whereas the OP in that question was SSHing to a NAS running Linux.

I was using git with GitKraken and was performing a merge that I later aborted. During the merge I was diffing two files from two commits in the same branch and git (or GitKraken – I'm not sure who was responsible for the file, exactly) created two files on-disk representing a merge-conflicted file, each file represents the file's state from each commit.

When I was done, I tried to delete the files (it failed to clean-up after itself) – one of the two files was deleted successfully, but the other file cannot be deleted.

Screenshot of Item Not Found error message

  • The file exists on a local volume (a Samsung PCI-Express NVMe SSD )
  • The volume is formatted NTFS 3.1 running Windows Server 2016
  • The file appears in Windows Explorer and dir (see screenshot above)
  • Attempting to perform any operation on the file in Windows explorer, including Move, Rename, Delete, and Shift+Delete, results in this error message:

    Item Not Found
    Could not find this item
    This is no longer located in C:\git\redacted\
    Verify the item's location and try again.

    DemoServiceClient.cs~WIP
    Type: File
    Size: 8.35KB
    Date modified: 2017-12-14 12:30

    [Try Again] [Cancel]

  • The File Properties dialog is empty:

    enter image description here

  • The File Properties dialog's Security tab says:

    The requested security information is either unavailable or can't be displayed

  • The total filename length is 130 characters, well within MAX_PATH (260 characters)

  • The file appears in dir /a as a normal file (i.e. not an NTFS link or reparse point):

     Directory of C:\git\redacted
    
    2017-12-14  12:36    <DIR>          .
    2017-12-14  12:36    <DIR>          ..
    2017-12-14  12:30             8,559 DemoServiceClient.cs~WIP.
                1 File(s)          8,559 bytes
                2 Dir(s)  223,416,360,960 bytes free
    
  • Running del DemoServiceClient.cs~WIP gives me this error:

    Could Not Find C:\git\redacted\DemoServiceClient.cs~WIP`

  • chkdsk reported no issues:

    Stage 1: Examining basic file system structure ...
      1140992 file records processed.
    File verification completed.
      19089 large file records processed.
      0 bad file records processed.
    
    Stage 2: Examining file name linkage ...
      1527444 index entries processed.
    Index verification completed.
      0 unindexed files scanned.
      0 unindexed files recovered to lost and found.
    
    Stage 3: Examining security descriptors ...
    Security descriptor verification completed.
      193227 data files processed.
    CHKDSK is verifying Usn Journal...
      34291080 USN bytes processed.
    Usn Journal verification completed.
    
    Windows has scanned the file system and found no problems.
    No further action is required.
    
     499526655 KB total disk space.
     290439980 KB in 856509 files.
        464848 KB in 193228 indexes.
             0 KB in bad sectors.
       1258155 KB in use by the system.
         65536 KB occupied by the log file.
     207363672 KB available on disk.
    
          4096 bytes in each allocation unit.
     124881663 total allocation units on disk.
      51840918 allocation units available on disk.
    

Best Answer

I had the same problem and found a solution here.

Edit: You will HAVE to move/rename the file into a folder you can delete with the provided solution (or check if you can already delete the file's parent folder, if possible).

Edit2: NTFS (or Windows itself) does not like/allow for file names to end with a dot or a space. You need to remove the dot/space from the file/folder name. You may need to to it from a DOS prompt (CMD), but then you may also be able to just delete it from CMD.

Commands to try: del, rd, move and ren

Here goes Rayza73's answer for reference.
I tried pretty much all he did, and also tried renaming the folder a few times.

I had this same problem using Server 2012 Std. I tried various options of taking ownership of the parent folder because the Security properties of the folder I was trying to delete were blank, using CMD and Dir /x etc. I even tried sharing the parent folder and then using Server 2008 R2. None of them worked. When I tried Dir /x Server 2012 doesn't show the 8 character filename with the ~1. I tried typing it in myself, but that didn't work either. I then found that there was a space at the end of the folder name. I then tried all the CMD options again using a space, still no luck. Then I finally stumbled upon this solution:

Open CMD and then type:

rd /s "\\?\D:\bad\folder\path "

example:

rd /s "\\?\D:\Sharedata\folder1\folder2 "

note the space after folder2 as per the space in the folder name.
Obviously D: is the drive that has the folder on it.

In my case there was no space or dot in the end of the folder name, just a stubborn folder left on a failed Teracopy run. But my folder had several folders inside it that could not be deleted.

This did the trick.

My run was:
rd /s "\\?\G:\Backups\MacMini\BADFOLDER"

If it is a file instead of a folder, just adjust the command. The command rd stands for "remove dir", so it makes no sense to use it in a file:

del "\\?\D:\Mainfolder\folder1\myfile."

You could also try to move it somewhere else before deleting it, if you are having problems.

Tip: You can use TAB to autocomplete the Files and Folder names in cmd. Repeating TAB will give you the next choice.