How do I access a file on Windows with an invalid filename?

I recovered a file using Recuva from (I believe) a FAT32 file system to an NTFS file system with Windows 10 installed. The file had a space in its name: The Grilling . In Windows, I know that filenames with trailing spaces aren't allowed, but somehow Recuva created it anyway. However, I can't rename or delete the file. When I try to do so in Windows Explorer, I get an error:

"Cannot find this item" error message

I know it has a space in its name:

Explorer with the file name selected, showing it has a trailing space

I then tried to do rename it with the Command Prompt. Tab completion reveals the file to have a trailing space, but it doesn't recognize the file:

C:\...>rename "The Grilling " "The Grilling-"
The system cannot find the file specified.

C:\...>rename "The Grilling" "The Grilling-"
The system cannot find the file specified.

C:\...>rename "\\.\\C:\\...\\The Grilling " "The Grilling-"
The system cannot find the file specified.

C:\...>rename "\\.\\C:\\...\\The Grilling" "The Grilling-"
The system cannot find the file specified.

I can manipulate its parent folder, but I can't do anything to the file. How can I rename the file so I can access or delete it?

Answers 1

  • Find out the file's 8.3 name by using the dir /x command, then run del followed by the file's 8.3 name to delete the file.

    Animated picture showing the process

    To rename (let's say the file is on the desktop and you want to rename it to The Grilling.avi):

    ren "\\?\%userprofile%\desktop\The Grilling " "The Grilling.avi"
    

Related Questions