How to delete a file with a too long path or its name contains invalid characters. If you’re having trouble deleting a file that Windows thinks is “too long”, there is a very simple solution built right into Windows — no additional applications, hacks, or workarounds are required.
Some Windows 10 users experience the “Destination path too long” error when moving or copying files from their original location to another folder or drive. Windows has a limit on the number of characters that is applied by default to a file path, which is normally 260.
When you try to copy a file from a location, the calculated destination path is the sum of the characters that exist in the source path and the file name. And since that number is over 260, you run into the Destination path too long issue.
Another issue is that many apps are unable to work with files that contain characters like a double space or dots at the end of the file name, or just some invalid characters.
This tutorial will show you how to delete a file with a too long path or which contains invalid characters in its name on Windows 10.
Delete File When Path Too Long or Name Ends with Dots or Space
- Open a new command prompt.
- Type a command like this
del "\\?\C:\some-long-path.doc"
. Substitute the path portion with the actual file path. - For a file name that ends with a space, type the following command:
del "\\?\C:\some-path.doc "
. - Finally, for the file name that ends with dots, type
rd /s "\\?\C:\full-path.."
. - Hit the Enter key to remove the file.
Here’s how it works. You need to use the prefix \\? \ followed by the full path to the file or folder, including periods or trailing spaces if necessary. The \\? \ prefix is used in the Win32 file namespace. If it is specified, the API on Windows does not process the path string, but immediately sends it to the file system. The File system itself doesn’t have such a limitation for the path length or file name.
Also in Windows 10, you can enable native long path support. After that you will be able to remove files from File Explorer without issues.
Remove files with long path from File Explorer
- Open the command prompt as Administrator.
- Run this command
reg add "HKLM\SYSTEM\CurrentControlSet\Control\FileSystem" /v LongPathsEnabled /t REG_DWORD /d 1
. - Reboot the computer to apply the change.
- Now, delete the file from File Explorer, e.g. select it and press Del on the keyboard.
Finally, some of the files may include invalid characters in the path. For example, the following characters are not permitted for being used in file names.
< (less than)
> (greater than)
: (colon)
” (double quote)
/ (forward slash)
\ (backslash)
| (vertical bar or pipe)
? (question mark)
* (asterisk)
If a file contains one of these symbols in its name, Windows will show a error message.
del /s /q \\?\C:\Users\Corrupted\*
The file or directory is corrupted and unreadable.
In this case, you need to perform the disk check.
Check the file system for corruption
- Open a command prompt as Administrator.
- Type
chkdsk /f C:
. Substitute the drive letter with the drive you have your files on. - Hit the Enter key.
- If prompted to restart the OS, reboot it.
If the volume is in use, the check will start after reboot. The files will be moved to a hidden folder like Found.000 in the root of the drive.
If nothing above helps, you can also remove the files by adding them to an archive using 7-zip. This open source archiver has no issues with file removal, even it has a lengthy path or invalid characters.
Remove files you cannot delete normally using 7-zip
- Download 7-zip from the official web site.
- Install it.
- Right-click on the folder that contains files you issues with, and select 7-zip > Add to archive.
- Check Delete files after compression.
The 7-zip tool works directly with the file system, and has no limitations with file paths and names. This way it can remove both long paths and files with invalid names.