Can't delete files on NTFS file system

Cause 6: The file name includes an invalid name in the Win32 name space

You can't delete a file if the file name includes an invalid name. For example, the file name has a trailing space or a trailing period, or the file name is made up of a space only. To resolve this issue, use a tool that uses the appropriate internal syntax to delete the file. You can use the "\\?\" syntax with some tools to operate on these files. Here's an example:


del "\\?\D:\<path_to_file_that contains a trailing space.txt>"


The cause of this issue is similar to Cause 4. If you use typical Win32 syntax to open a file that has trailing spaces or trailing periods in its name, the trailing spaces or periods are stripped before the actual file is opened. For example, you have two files in the same folder named AFile.txt and AFile.txt , note the space after the file name. If you try to open the second file by using standard Win32 calls, you open the first file instead. Similarly, if you have a file whose name is just a space character and you try to open it by using standard Win32 calls, you open the file's parent folder instead. In this situation, if you try to change security settings on these files, you either may not be able to do so, or you may unexpectedly change the settings on different files. If this behavior occurs, you may think that you have permission to a file that actually has a restrictive ACL.

Source: https://learn.microsoft.com/en-us/troubleshoot/windows-server/backup-and-storage/cannot-delete-file-folder-on-ntfs-file-system