Wednesday, October 24, 2012

Can't Delete File/Folder: "The file name you specified is not valid or too long"

Once I got this error message "The file name you specified is not valid or too long" when I tried to delete a folder.  The reason was that this folder has content with very deep folder structure. I googled and tried many methods mentioned by various users without any use. Finally, I found a very smart and simple solution by an anonymous user at "http://www.tomshardware.com/forum/198314-46-deleting-file-path-long". Below is the resolution as  stated by that user:

"One simple method I've used in the past to manage folder trees longer than 
MAX_PATH is to break the trees into chunks. So.. 
Traverse the directory as deep as you can within Explorer or the command 
shell. Then move all the contents below it to the root of the drive (or a 
folder under the root) so you now have a second directory tree. If the new 
tree is still greater than MAX_PATH, repeat until you get a manageable tree. 
What you do with the multiple directory trees is your business, but at least 
they're manageable"

So, basically, I cut and paste the directory structure to the driver root, and then, I was able to delete it.