Getting Around Windows 7 "Destination Path Too Long" Error When Deleting Files

Years ago when I started learning VBA for Excel, I was reading a book by John Walkenbach and he compared learning macros in Excel to using a remote control - once you learn it you don't know how you lived without it. I would say that is true of scripting in general.

The bad news is that programming is also like using a credit card, inasmuch as you can get yourself into a depth of problem just not possible without it.

I got experience with that first hand recently when one small programming mistake caused a bit of a disaster on my computer.

My plan was that I would write some automated tests to test a vanilla installation of the Neptune framework. As part of this, I back up my CustomTags folder by renaming it "CustomTag_BAK" - easy enough.

Unfortunately, I made a mistake while making some changes that caused it to copy "CustomTags/_BAK". Worse yet, I did this using a recursive bit of code (if programming is dangerous, recursion is doubly so). The effect of which was several levels deep of "_BAK" folders in my CustomTags folder.

Actually, "several" doesn't cut it. It was thousands of levels deep. I'm not sure how many as Windows seemed to stop counting. This seemed an easy problem to solve, however. I just highlighted the folder on clicked delete.

"Destination Path Too Long"

The problem is that Windows cannot delete a file whose path is longer than 256 characters long. It will let you create files with paths longer than this, but not delete them.

So, how to fix it? Well, I found a page by Microsoft that suggested some solutions (which I'll simplify a bit).

Rename the folder names

This is a nice idea, but as I have more than 256 folders, it really won't help.

Manually move the file to another folder

This is a good solution if the problem is that the folder is just a little bit too long. The problem is that if the folder you move is still too long then you still can't delete it.

So, in my case, I would have to find the deepest folder and start from there. Several minutes of clicking to get there showed me that I was no closer to it then when I started.

Create a virtual drive

This would work well if my folder depth totaled less than 256 X 26 characters long (that is the character limit times the number of letters in the alphabet and thereby the number of virtual drives I could create). Again, my problem was much worse than this.

At this point, I have to admit that I was feeling a little concerned. Here I start to consider just dumping my computer and restoring from back-up. Unfortunately, due to not noticing the problem quickly enough this will mean that I either restore from a back-up that has the problem I am trying to fix or from one that is missing some of what I need (or go through a painful process of cherry-picking files).

Nope, there has to be a better way.

Fortunately there is (or this would be a depressing blog entry).

Move the files with a Script

Someone (I can't find who anymore, sorry) wrote a nice .bat file that (with a little bit of editing) solved by problem. They named the file "recupera.bat", so I kept that name.

recupera.bat:

ren c:\ColdFusion9\CustomTags\_BAK\_BAK x

move c:\ColdFusion9\CustomTags\_BAK\_BAK\x c:\ColdFusion9\CustomTags\_BAK

rd c:\ColdFusion9\CustomTags\_BAK\_BAK

ren c:\ColdFusion9\CustomTags\_BAK\x _BAK

repucera.bat

So, what does this do?

ren c:\ColdFusion9\CustomTags\_BAK\_BAK x

This takes "c:\ColdFusion9\CustomTags\_BAK\_BAK" and renames it to "c:\ColdFusion9\CustomTags\_BAK\x". Apparently Windows has no problem renaming paths even if the result is a path that is too long for it to work with.

move c:\ColdFusion9\CustomTags\_BAK\_BAK\x c:\ColdFusion9\CustomTags\_BAK

This moves all of the files from "c:\ColdFusion9\CustomTags\_BAK\_BAK\x" to "c:\ColdFusion9\CustomTags\_BAK". So, now "c:\ColdFusion9\CustomTags\_BAK" has two folders: "x" and "_BAK". The "x" folder still has tons of subfolders, but the "_BAK" folder is empty.

rd c:\ColdFusion9\CustomTags\_BAK\_BAK

This just removes the now empty nested "_BAK" folder.

ren c:\ColdFusion9\CustomTags\_BAK\x _BAK

This renames the "x" folder (which has tons of nested "_BAK" folders) back to "_BAK". Now my situation is the same as when I started except that one folder has been removed.

repucera.bat

This just executes the .bat again - a nice loop. At some point the "ren" line will throw an exception because the "c:\ColdFusion9\CustomTags\_BAK\_BAK" will no longer exist. This will stop the loop. At this point the problem is finally solved.

So, if you ever find yourself in the bind that I created for myself then feel free to take this code and modify it to suit your problem (renaming the path to the location of your problem).

Hopefully I will never need this again.

Comments
Hi,

This problem is no longer a considered a hassle because it has been solved.

There is away to fix this problem and the name of that software is LONG PATH TOOL.

I highly recommend it to you since I have already used it.

check it out: http://longpathtool.com
# Posted By Cristopher Neil | 3/12/12 9:19 PM
Yeah, I saw that tool when I was searching for a solution. I just don't like installing extra software on my computer that isn't needed (limited trust, I suppose).

In this case, the solution was simple enough that installing software wasn't necessary.
# Posted By Steve Bryant | 3/13/12 8:57 AM
I like this trick. This trick is good for users who love to play with technical ways. However, I have used “Long Path Tool” in this situation and it helped me easily and quickly. So this tool is best for those members who don't love to play with technical skills.
# Posted By Ethangreg | 3/15/12 2:15 PM
The Long Path Tool is advertised as freeware but you actually need to buy a license to get it to work.
# Posted By David Schulberg | 8/13/12 3:39 AM
I tried this, but I get access denied on the very first iteration. :-( Any other suggesions would be greatly appreciated.
# Posted By KT | 8/24/12 8:13 PM
PS - I own the machine and all the subdirectories and I am local admin on this machine, as well.
# Posted By KT | 8/24/12 8:14 PM
KT,

It has been a while since I did this, but you may have to right-click on command prompt and select "Run as administrator" in order for the commands executed from there to have permissions to do this.

Window 7 is kind of weird about that kind of stuff.
# Posted By Steve Bryant | 8/24/12 8:56 PM
every thing said by gabriel nar is fake as fake as his website and softs it's just a scam
# Posted By GabrielNar is fake | 9/21/12 3:54 PM
I believe you are right. I have removed all of those posts and marked that domain as spam internally.

Thanks,

Steve
# Posted By Steve Bryant | 9/22/12 12:50 PM
To clear very long name ( with setACL.exe before for rights) use:

robocopy...

robocopy C:\EMPTY_DIRECTORY C:\DIRECTORY_WITH_SUB_OR_FILE_TOO_LONG\...\ /PURGE /W:1 /R:1 /V /S

result a false copy but that clean up all...

enjoy!
# Posted By Fred | 9/25/12 7:56 AM
robocopy C:\EMPTY_DIRECTORY C:\DIRECTORY_WITH_SUB_OR_FILE_TOO_LONG\...\ /PURGE /W:1 /R:1 /V /S

result a false copy but that clean up all...

This WORKS! I had Google Drive installed and it made a folder structure that was 705 folders deep! I've been trying to delete them for DAYS, but nothing worked until I used this line in the command prompt (I was running CMD as ADMINISTRATOR, not sure if it mattered). I know this post is old but STILL RELEVANT! Thank you for posting it!
# Posted By Brian | 9/3/14 10:28 AM
Hello smiley for :D
are you looking how to copy, delete, long path files or something like
copy file path is too deep the path is too deep network copy the path is too deep usb path too deep solution path too deep error path too long error windows 8 cannot copy path too deep error copying file the path is too deep can't copy path is too deep cannot copy file path too deep error copying file or folder the path is too deep what does the path is too deep mean path too deep windows xp cannot delete file cannot find the specified path get path too deep error when copying files over vpn cannot copy file the path is too deep path too deep error message can't copy path is too deep path too deep solution path is too deep xp path too deep windows xp the path is too deep usb error the path is too deep cannot copy the path is too deep windows xp path too deep usb cannot copy the path is too deep error file path too deep cannot copy the path is too deep windows xp error copying file the path is too deep error copying file or folder the path is too deep error 1320 the path is too long windows 7 error 1320 the specified path is too long windows 7 too long path windows 7 path too long pro destination path too long path too long error when extracting zip file path too long to delete error 1320 path too long windows 8 error 1320 the path is too long windows 7 windows 7 path too long to delete windows 7 destination path too long delete windows path variable too long windows path too long solution destination path too long fix windows 8 filename too long windows 7 path too long pro path too long error when extracting zip file path too long error when extracting zip file destination path too long error error 0x80010135: path too long windows path variable too long windows path too long delete windows path too long solution path too long tool file name too long for destination folder filename too long workaround how to copy long file names in windows 7 the filename would be too long for the destination folder delete path too long android sdk file name s would too long reason for not to copy destination folder too long to copy file name too long to copy windows 7 find long file names windows xp filename length filename too long for destination folder the file name(s) would be too long for the destination folder file names too long windows 7 filename too long long file names windows 7 cannot delete filename too long windows 7 find long file names windows 7 256 character limit windows the filename would be too long for the destination folder windows 7 filename length the filename or extension is too long 256 character limit windows windows 7 file name restrictions file path length limit windows 7 source file name are larger than is supported by file system filename too long to delete windows 8 the source filename are larger than is supported by the file system shadow copy the source file names are larger than is supported by the file system the source file names are larger than is supported by the file system previous versions the source file names are larger than is supported by the file system folder the source file name(s) are larger than is supported by the file system path 255 characters maximum path length windows 7 windows path limit windows 7 path length limit 256 character limit windows windows file path long file path destination path too long max_path windows 256 character limit windows 2008 windows 7 path length limit cannot delete filename too long windows 7 max_path windows maximum file path length windows 7 windows 7 filename length destination path too long.
the solution is simple visit http://www.webhostingtalk.com/showthread.php?t=112...
Thanks
# Posted By Habibur Rahman | 3/28/15 6:09 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.