Windows uses the Win32 namespace to determine the validity of file and folder names. One of the rules, according to the namespace, is that the names cannot contain a trailing space or period (dot). So something like “file.txt.”
or “file.txt ”
(notice the space at the end) would not be valid.
However, there are situations where you can create or have such files or folders. Whenever you try deleting, renaming, moving, or copying such a file or folder, Windows will treat it as if its trailing space or period is not there. So it’ll search for some other item instead.
In such cases, you’ll get an error message that says “Item Not Found. Could not find this item. This is no longer located in …” To resolve this issue, you need to use some means that do not depend on the Win32 namespace, which we have explained below.
Delete or Rename Through Command Prompt Using Long Device Path
The easiest way to solve this issue is by using the long device path of the file/folder according to the Universal Naming Convention while deleting the file. This path uses the \\?\
syntax before the absolute path.
Each file or folder contains a path that helps determine the exact location of the file/folder. For instance, The folder System32 inside the Windows directory of the C drive has an absolute path C:\Windows\System32
. And its long device path is actually \\?\C:\Windows\System32
This type of path ignores any invalid characters in the path name, so you can safely use it to delete or rename the file showing the above error. You will have to use command-line interfaces like the Command Prompt and use the long device path with the respective commands for this purpose.
- Open Run by pressing Windows key + R.
- Type
cmd
and press Enter to open the Command Prompt. If the file or folder showing this error is inside your system directories (usually inside Program Files or Windows or other user files), you need to typecmd
and press Ctrl + Shift + Enter to open the Elevated Command Prompt instead. - Use the commands below depending on whether you wish to delete or rename the file.
- To delete a file, type
del "\\?\<Full path of the file>"
and press Enter.
For instance, if you wish to delete the file “random.txt ” (notice the trailing space) inside the D:\New folder, you need to use the commanddel “\\?\D:\New\random.txt ”
- To delete a folder, type
rd "\\?\<Full path of the folder>"
orrmdir "\\?\<Full path of the folder>"
and press Enter.
So, if the folder is “D:\New\Error ” (with the trailing space), you need to use the commandrd “\\?\D:\New\Error ”
- To rename the file, type
ren “\\?\<Full path to the file>” “<New file name>
and press Enter.
For instance, if the file is“D:\New\random.txt ”
, use the commandren “\\?\D:\New\random.txt ” “random.txt”
- You can’t rename a folder this way. So you’ll need to move its contents to a new folder and then delete the folder. The commands for “D:\New\Error ” are as follows
md “D:\New\Error”
(without trailing space)move “\\?\D:\New\Error \*” “D:\New\Error”
rd “\\?\D:\New\Error ”
If you get the error “The filename, directory name, or volume label syntax is incorrect.” while using themove
command, it means that the folder is empty, and you can safely remove it.
- To delete a file, type
Mirror an Empty Folder Using Robocopy
It is also possible to resolve this issue by forcefully deleting the error file or folder in the following way:
- Make it the sole file or folder inside its parent folder.
- Mirror an empty folder to this folder.
You can use the robocopy
command with the /mir
option to mirror the empty folder.
However, remember that you can only delete the folder or file using this method. If you need to rename it (or move/copy), it’s best to use the above method instead.
- First, move all the other contents of the directory containing the folder or file with the error somewhere else. For instance, if the error occurs in
“random.txt ”
inside D:\New, move all other files and folders except“random.txt ”
somewhere else. This way,“random.txt ”
is the only item inside D:\New. - Then, create an empty folder in any location. I’ve created the folder
Empty Folder
insideD:
for this example. - Open the Command Prompt (cmd in Run).
- Type
robocopy “Empty folder path” “Path of parent folder of error file/folder” /mir
and press Enter. In this example, the command would berobocopy “D:\Empty Folder” “D:\New” /mir
- Move back the previous contents of the parent directory.