Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I was working with some computer vision source code I found and didn't realize that it creates a cache file that has a VERY LONG name and now I can't delete the 2 of them.

I tried to rename it to a shorter name but I can't do anything to the file, I also tried to restart my computer and see if it would just go away.

The error message says:

Destination Path Too Long.

The file name(s) would be too long for the destination folder. You can shorten file name and try again, or try a location that has a shorter path.


How can I delete the files in this case?

share|improve this question

marked as duplicate by Keltari, Ƭᴇcʜιᴇ007, Journeyman Geek May 17 '14 at 9:38

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Would it work from the command line with the del command? Something along the lines of del *.cache should delete all .cache files in the current directory. – Ryan May 16 '14 at 20:14
"Path\to\folder\CACHEI~ The system could not find the file specified" said that twice and there's 2 files in there but didn't do anything – Duck May 16 '14 at 20:17
On second thought, you could check one of the other questions that has already been answered. This one for example. – Ryan May 16 '14 at 20:18
If these two files are the only ones left in the directory, then you may have better luck deleting the entire directory. From the command prompt, try rd /s directoryname This will wipe out directoryname and all files/subdirectories within it, so use it with caution :) – bitsmack May 16 '14 at 20:22
A folder containing files with total path too long cannot be deleted from the GUI, due to the files within that have the too-long path. – Debra May 17 '14 at 6:40

4 Answers 4

up vote 128 down vote accepted

Assuming you are on windows:

What I always do is use subst to create a driveletter asccociation with part of the path.

Then go to the new driveletter and navigate to the files that have long names. You should now be able to rename/delete/etc them. The reason this works is because the path itself is no longer containing >255 chars.

To create a subst folder

  1. Start a commandprompt (no admin privileges needed)
  2. Use cd to navigate to the folder you want to go (you can use tab to autocomplete names
  3. type subst j: . to create the driveletter association. (instead of the . you can also type the entire path)
  4. Now in explorer you have a new letter. Go to it and do whatever you need to do to the .cache files.
  5. Go back to your cmd window and type subst /d j: to remove the drive or alternatively, restart your pc.
share|improve this answer
thank you so much! that worked – Duck May 16 '14 at 20:24
Wow Microsoft. Wow. – SgtPooki Sep 25 '14 at 19:52
robocopy empty_dir base_nested_dir /purge -- Just create an empty directory, and tell robocopy to purge everything in the target directory which isn't in the empty directory – rofrol Oct 30 '14 at 8:54
Just tried this and i could not remove the file in question.. I use cygwin with windows, an alternative solution is to remove the file that way: rm -R /path/in/question as long as no other program is using the file you are good to go – John Mar 3 at 17:28
I had an issue where SUBST didn't recognise J: as a parameter (it also didn't see any virtual drives that were available) so the cygwin option mentioned by John worked well. – Tisch Apr 1 at 12:40

Your question asks how to delete a file when the filename itself is too long. If the path is too long and not just the filename itself, you can easily just rename the folders to make the path shorter.

But to delete a file whose name is more than 255 characters:

  • Open a command prompt by running "CMD.EXE"
  • Navigate to the folder holding the file
  • Use the command DIR /X which will display the short names of files.
  • Delete using the short name.

i.e. if the file is named "verylongfilename.fil", the shortname will display as something like "verylo~1.fil" and you can delete using that name.

Please note that although Windows itself can handle paths far longer than 255 characters, most of the GUI -- like Windows Explorer -- is bound by the shorter limit.

share|improve this answer
This is a better answer than the accepted on. – Ben Jan 16 at 21:06
Far better answer, thank you! – Steffen Müller Jan 26 at 12:54
This too… – Pacerier May 16 at 0:25
The chosen answer is better because you can delete whole folders with that method – Matteo May 28 at 19:08

Googled: delete long filename First result

Use Unlocker

Cannot delete folder: It is being used by another person or program Cannot delete file: Access is denied There has been a sharing violation. The source or destination file may be in use. The file is in use by another program or user. Make sure the disk is not full or write-protected and that the file is not currently in use.

Unlocker can help! Simply right-click the folder or file and select Unlocker. If the folder or file is locked, a window listing of lockers will appear. Simply click Unlock All and you are done!

share|improve this answer
I did see that but didn't know if unblocker was safe to use so I ignored it, I'll try it out. EDIT: didn't work. it works on other files but unblocker doesn't appear in the drop down – Duck May 16 '14 at 20:20
Certainly the simplest way to do it, although it may need a reboot to complete. Nothing wrong with Unlocker at all - been using it for years and it's a very useful utility. In the case of a file or folder whose path is too long it will find no locking handle but should offer the Delete option in the drop down afterwards. – Steve Pettifer Jan 12 at 14:55

Microsoft has a useful knowledge base article on deleting undeletable files. Cause #4 is of relevance to you.

Your best bet would probably be to map a drive to the folder that file is in (resolution #3), then enter in through that drive and delete it.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.