Subscribe

Get the Network Administrators tool pack

Subscribe to our newsletter and get 11 free network administrator tools, plus a 30 page user guide so you can get the most out of them.

Click Here to get your free tools

Recent Posts

Search

Archives

Easy solution for “Cannot delete “file name”: The file name you specified is not valid or too long.”

Post image for Easy solution for “Cannot delete “file name”: The file name you specified is not valid or too long.”

by Steve Wiseman on February 13, 2015 · 6 comments

in Tips,Tools


.

I am almost positive you have run into this error before. Recently I have had 1000s of files like this.

File is too long

Where did they come from? Both times it was a hidden cache folder for DropBox and AeroFS. I had been playing with both to see if I wanted to use them to sync my files.

Well, I found a simple way to blow these away in one shot, and you can use a tool within windows to do it.

It seems that robocopy can handle these long file names. What you do is you create an empty folder, and then use it to synchronize the copy while telling it to delete all the files that do not exist in the source (Your empty folder)

So if you are running into this, and just want the whole folder gone, get to a command line and create an empty folder.

I created one at c:\empty

And lets say for our example here the offending folder is c:\BadFolder

You would call robocopy like this:

robocopy c:\empty c:\badfolder /e /mir

Mirror file command

The /e tells it to visit all sub folders even if they are empty, the /mir will tell it to delete any file or folder that does not exist in c:\empty – which is everything.

So there it is. A simple trick to get around those pesky files that windows says are too long – no special tools needed.

Just keep in mind this will delete *everything* not just the long file names. So please think carefully before you use it

One more thing…Subscribe to my newsletter and get 11 free network administrator tools, plus a 30 page user guide so you can get the most out of them. Click Here to get your free tools

Related Articles:

{ 6 comments… read them below or add one }

1 Mark February 13, 2015 at 12:25 pm

Fantastic tip. I have run into this quite a few times, and so far this is the easiest solution I have ever seen.

2 Dave Ponky February 13, 2015 at 12:26 pm

Hi Steve,

I hope you are feeling better, and glad to see a new tip this week. This one is a a gem.

3 Leonard February 13, 2015 at 1:58 pm

Hi Steve,
Thanks for this, I was faced with this issue today, before your mail came thru, and I copied the offending folder while selecting to skip these files as windows couldn’t read them.
Robocopy is much better, I think.

4 Simad February 15, 2015 at 1:43 pm

For such a problem I simply rename the parent folder to a shorter name; Simpler and safer. You can rename the parent folder back to its original name once you delete the target folder or file.

5 Troy May 28, 2015 at 5:11 pm

Thank you very much for this! I have a 2012R2 box with Mac Files and this happens sometimes with Mac Font files that are 0 bytes in size.

Thank you, thank you, thank you!

6 cristopher March 7, 2016 at 11:26 am

I used to have similar problems too, but after using “long path tool” everything was solved. Try this software and you would be glad you did.

Leave a Comment

Category Links - Windows Forum - Exchange Forum