Delete File When Path Too Long or Name Ends with Dots or Space

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.

Delete File When Path Too Long or Name Ends with Dots or Space

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

  1. Open a new command prompt.
  2. Type a command like this del "\\?\C:\some-long-path.doc". Substitute the path portion with the actual file path.
  3. For a file name that ends with a space, type the following command: del "\\?\C:\some-path.doc ".
  4. Finally, for the file name that ends with dots, type rd /s "\\?\C:\full-path..".
  5. 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

  1. Open the command prompt as Administrator.
  2. Run this command reg add "HKLM\SYSTEM\CurrentControlSet\Control\FileSystem" /v LongPathsEnabled /t REG_DWORD /d 1.
  3. Reboot the computer to apply the change.
  4. 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

  1. Open a command prompt as Administrator.
  2. Type chkdsk /f C:. Substitute the drive letter with the drive you have your files on.
  3. Hit the Enter key.
  4. 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

  1. Download 7-zip from the official web site.
  2. Install it.
  3. Right-click on the folder that contains files you issues with, and select 7-zip > Add to archive.
  4. Remove files with invalid charactersCheck Delete files after compression.7 Zip Delete 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.

Looks like you've read the post to the end. If you enjoyed it, please share it. You would greatly help our blog to grow!

Author: The MFTNEXT Team

The MSFTNEXT project is a small team of authors who love to engage with the latest technology and gadgets. Being passionate Windows bloggers, we are happy to help others fix their system issues.

Leave a Reply

Your email address will not be published.