Sunday, September 27, 2015

How to delete a file with a path too long for normal delete

I was working with some computer vision source code I found that it creates cache file that has a VERY LONG name and now
I can't delete entire folder due that file.

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:
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.

After doing lot of things I found an easy way of removing  a file with a path too long to be deleted. So simply


  1. Run cmd as Administrator (you might don't need it).
  2. Change path to the directory that file is located or the parent folder.
  3. I'm using robocopy command to get this done. finally run following commands. Because when you want to completely delete a directory and it has file with long names inside it, robocopy does a VERY good job for you.☺

mkdir empty_dir
robocopy empty_dir the_dir_to_delete /s /mir
rmdir empty_dir
rmdir the_dir_to_delete

3 comments:

  1. Hi Aruna,
    Thanks for sharing this post. I have been using long path tool for this issue. It is very easy to use and It can delete, copy, move and bulk rename long path files or locked file easily.

    ReplyDelete
  2. I suggest you try Long path tool is the very good program for easily delete, copy & rename long path files, error, unlock solution.
    Try it and solve your problem.

    ReplyDelete
  3. Try to use Long Path Tool, it really can help you with that.
    It will really help you to solve your problem.

    ReplyDelete