Fix: Cannot Delete File, The File Name You Specified Is Invalid Or Too Long - gHacks Tech News

Fix: Cannot Delete File, The File Name You Specified Is Invalid Or Too Long

Files or folders can sometimes not be deleted because of file name restrictions in Windows. See, Windows supports file names of up to 255 characters, which includes the directory path. If a directory or file surpasses that limit it cannot be deleted. Many users at this moment assume a corrupt file on the hard drive that is preventing the deletion. While that is a possibility, it may be simpler than that.

The error message reads (variants possible):

cannot delete file: the file name you specified is invalid or too long. Specify a different file name.

The following trick may help in removing the file and the directory structure from the system. Please note that it is not necessary to count the characters used in the file path, if it looks extraordinarily long then it may use indeed more characters than the allowed maximum.

the file name you specified is not valid or too long

We have already established that deletion does not work. The best option? Renaming. It is still possible to rename directories or the file name, so that the total count drops below the character limit. This can be done both in Windows Explorer, or on the command line. Just select a folder, and rename it to a single character. Repeat the procedure until the file path length has dropped considerably.

Deleting the file and folder structure should then work both in Windows Explorer and the command line. There are other solutions on how to cope with this situation. Another possibility is to map a drive to a folder in the path, to shorten the url structure, or to find a software or operating system that can manipulate those files and folder structures.

Did you ever encounter files that could not be deleted because of their length? What have you done to fix the situation?

You may also ask yourself how those structures appear on your system. It can be that you have downloaded and extracted an archive that included a nested folder structure, or are using a data drive on Windows and another operating system that does not have these restrictions. Whatever the reason, your best bet of deleting, renaming or moving files or folders if you receive the "not valid or too long" error is to shorten its path by renaming folders.

We need your help

Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.

We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats or subscription fees.

If you like our content, and would like to help, please consider making a contribution:

Comments

  1. Mehdi S said on August 15, 2010 at 5:19 pm
    Reply

    unlocker ftw…

    1. Martin said on August 15, 2010 at 5:23 pm
      Reply

      I do not think that Unlocker can help in this case.

      1. Mehdi S said on August 16, 2010 at 7:30 pm
        Reply

        Maybe I’m wrong, but i’d swear I used unlocker for that bug before…As for your trick, I used to do that too :)

  2. FL said on August 15, 2010 at 7:12 pm
    Reply

    I understand an embedded feature of windows is the virtual impossibility or removing ‘too long’ file names. Often they are created when visiting websites and therefore may contain information a user want’s to delete.

    One way to circumvent such issues is to use sandboxie (http://www.sandboxie.com) by ensuring that the software/browser that creates such ‘too long’ file names is captured within a sandboxie container. The container can also be placed on a ram disk, so everything just vanishes at shutdown.

    The container could also be placed on a separate disk or usb stick, which can be overwritten/erased/formatted when needed.

    The only way to give accurate advice is to be advised which program created the file name or cut and paste a copy of it here, indicating which folders it is contained in.

  3. jasray said on August 15, 2010 at 7:45 pm
    Reply

    Hmmm . . . should be able to go to Task Manager, end process –explorer.exe, delete file, and restart explorer.exe. Maybe MoveOnBoot. Hard to say–heard about the problem; never had to personally deal with it.

  4. Bruce said on August 15, 2010 at 8:41 pm
    Reply

    Unlocker dose work. I use it in the field for this exact problem.

  5. paul(us) said on August 15, 2010 at 8:55 pm
    Reply

    Martin, Mehdi S is right i often encounter this problem and unlocker is always doing, the trick for me. Great program.

    1. Martin said on August 15, 2010 at 9:05 pm
      Reply

      Great, did not know that.

  6. Mike said on August 15, 2010 at 9:42 pm
    Reply

    I am a fan of unlocker and have been using it for years. It’s one of my goto tools along with Sysinternals Process Explorer and other utils. BUT there are times when doing all of the above and using every other ‘delete/unlock’ tool will not work. What I have found is that the long filename and ‘directory not empty’ thing can be fixed by using a bulk file rename tool 1st renaming the file(s) and or directories incrementally like 001 etc., then deleting (sometimes still with unlocker). There are loads of freeware bulk file/dir renamers around so I won’t list them use Google. I see this alot with incomplete backup file restores.

  7. Rarst said on August 15, 2010 at 10:15 pm
    Reply

    From my experience Unlocker doesn’t help with overly long paths. I get such regularly at work with one of programs. There might be differences of Windows versions and other specifics of course, in my case it fails.

    I use batch script that recursively destroys folder tree with robocopy.

  8. Hysterian said on August 15, 2010 at 11:22 pm
    Reply

    Problem is in charset. Any program dont see this named file, some yes but cannot delete or run. Solution is rename it to normal system charset and then delete. Bigger problem is folder, if you use rename or copy, it makes copy to file, not a folder. scandisk or checkdisk cant correct this….. solution is to use a filemanager with correct charset (ascii)

  9. Will said on August 16, 2010 at 4:47 am
    Reply

    One of the options in unlocker is to rename the file / folder.

    Works fine for me every time I come access this mess. So I too vote for unlocker.

    Of course Microsoft should just fix the bug in the first place!!

  10. Carl said on August 16, 2010 at 4:47 am
    Reply

    I usually map a drive partway into the path and then dig into the mapped drive to delete the file.

  11. frank said on August 16, 2010 at 9:10 am
    Reply

    Did not have problems with too long ones, but with under windows in filesnames not allowed chars like the ” : “. It was impossible to rename the file. So just started Ubuntu Live CD and renamed the file. It might also work for too long filepaths?

  12. Colin said on August 16, 2010 at 12:16 pm
    Reply

    I have had some success using the DOS command SUBST to cut a long path down to a drive letter.

  13. Transcontinental said on August 16, 2010 at 3:49 pm
    Reply

    I haven’t had exactly this problem but one similar to, which was having a zero-bite file unable to remove because the system just couldn’t read it, for the system there was no such file ! That was a few years ago and I had finally found an application which read and removed the file … I have an old version but the website and application are still going strong:

    JRT Wine Software, LLC – Delete FXP Files
    http://www.deletefxpfiles.com/index2.html

    If it can help as it had helped me, great !

  14. Kenneth M. Aspinwall said on August 16, 2010 at 7:06 pm
    Reply

    Unlocker works sometimes, but when it doesn’t, first I try to delete via a command line, if that doesn’t work then I use a live CD to boot into linux and delete the file(s) there.

  15. TSR said on August 17, 2010 at 6:01 am
    Reply

    I have this problem on a regular basis as Mac users on our server create directory structures 10 levels deep and then find they can’t rename or move a file. Windows has no problem creating the long paths but can’t delete them. The only thing that has work has been to create shares at some point in the path, delete the files, create a new share, etc. until the path is cleaned up.
    Of course, they will go and the same thing again the next day…

  16. Jehad said on August 17, 2010 at 10:17 pm
    Reply

    back in the time (the age of Windows 98 and ME) i used to go directlyto DOS booting and head to the directory of the file, since DOS will not show that very name (instead; it will shorten it with a hyphen in the end) you can so easily delete it.

    in case of Windows XP, the only way i remeber using was to go safe mode and delete the cursed file.

  17. The_Flames said on August 17, 2010 at 11:16 pm
    Reply

    I like the solution at this site :)

    http://www.rarst.net/script/delete-path-too-long/

    1. Rarst said on August 18, 2010 at 6:46 am
      Reply

      Heh, I should have probably linked to this in my comment above. :)

  18. damfiles said on August 18, 2010 at 12:24 pm
    Reply

    had this problem with a file downlaoded from net, too long a name and also Zero bytes, xp gave me no choice but to reinstall if i wanted rid of the dam file, xp didnt recognise it as a file because it was seemed to not even be a file, but there it was! and nothing i tried , renaming, going into dos to rename/delete !

  19. Diego said on August 18, 2010 at 2:27 pm
    Reply

    This command was a useful solution for me:
    SUBST

    Create a virtual drive from directory where the problem is, then try to delete/rename the stuck file/folder.

    Hope this help.
    Regards!

    1. Diego said on August 18, 2010 at 2:31 pm
      Reply

      Another terrific tool is FastCopy.
      http://ipmsg.org/tools/fastcopy.html.en

      Internally it bypass the 255 Windows chars limitations when copying/deleting.

  20. Ionut Stoian said on October 27, 2010 at 5:21 pm
    Reply

    Do you have error messages?, like :
    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.

    If yes, our progam will be helpful for you.

    Windows Explorer/FAR would fail to copy/delete/rename any pathname longer than 256 characters. Our program LONG PATH Tool can handle pathnames of any length, up to the internal Windows limit of 32,000 characters.

    Fast speed of long path folder/files search.
    No special system requirements. LONG PATH Tool works on any Windows version (NT/2000/XP/Vista/Windows 7).
    Delete system locked files
    Can delete files even from mapped network folders
    Can list files and paths which have file path more than 200 characters long.
    Close application that uses the file
    Unload locking process
    Copy and delete files and folders
    Delete after reboot
    Omits file name you specified is not valid or too long

  21. alan.larky said on December 31, 2010 at 7:04 am
    Reply

    i also have faced the same problme and following software sort out my problem

    http://www.longPathTool.com

    Little features of this softwares are:

    Path too long.
    Error cannot delete file: cannot read from source file or disk.
    Cannot delete file: Access is denied.
    There has been a sharing violation.
    Cannot delete file or folder The file name you specified is not valid or too long.
    Specify a different file name.
    The source or destination file may be in use.
    The file is in use by another program or user.
    Error Deleting File or Folder
    Make sure the disk is not full or write-protected and that the file is not currently in use.
    Path too deep.

    1. Ivanna Zhyljuk said on March 2, 2012 at 11:55 am
      Reply

      Just in case anyone is interested:
      long path tool moved to http://www.pathtoolong.com

  22. Baba said on December 18, 2011 at 10:37 am
    Reply

    I am also faced the same problem but i got the solution from the lonpathtool.com.

  23. Tom Ward said on August 5, 2012 at 11:12 pm
    Reply

    Use a software program called DelinvFile http://www.purgeie.com/delinv/index.htm

  24. Gurjot said on October 29, 2012 at 11:33 am
    Reply

    Followed the advice in this article by shortening the folder names successively to reduce the length of the file name, and voila! I was able to delete the offending files in a jiffy! Thanks for the simple solution.

  25. GabrielNar89 said on November 19, 2012 at 5:45 pm
    Reply

    This is a Windows* OS/file system issue.The cause is directory paths on the drive is longer than 255 characters (including spaces).There’s a lot of additional softwares which can fix this problem like Long Path Tool.
    http://PathTooDeep.com
    Long Path Tool can simplify and probably end your problems in unlocking, managing and renaming files that appear to have a long filename. Since in some instances, you may have experienced problems accessing, managing and even renaming files that have more than 255 characters, this utility has been made to answer this particular scenario. If you have also encountered problems like error messages that tell you that the path too long, too long path, destination path too long or cannot delete file then this program is definitely for you. This will totally take place of Windows Explorer, Far Manager or other file managing utilities since this is maybe used in any type of Operating System even the earliest Windows 95 version.

  26. Adrian Hauberg said on November 24, 2012 at 3:00 am
    Reply

    I was having this issues with my 2 gig SD card. I was unable to delete some (maybe corrupt) files because “the filename you specified is not valid or too long”. I couldn’t delete the files at all. I’m running windows 7. I fixed the issue by right clicking the SD file and then clicked “Format”. It erased everything on it. Of course, I was careful to make sure there was nothing on it that I cared about. Make sure you transfer all files that you want to save before doing this. They WILL be lost otherwise.

  27. Peter said on November 30, 2012 at 12:47 pm
    Reply

    Brilliant – what an easy solution: Renamed all folders to one letter and then could delete them. Thanks!

  28. JuliaBrin said on January 24, 2013 at 4:35 pm
    Reply

    Why don’t you check out Long Path Tool? It would be very useful, it would help you solve your problems. Check it out.

  29. novelltes karrychay said on February 6, 2013 at 3:38 pm
    Reply

    Have you tried long path tool it is the best software it will help you

  30. krowey said on February 9, 2013 at 2:11 am
    Reply

    Sometimes simplifying the file or folder name doesn’t work.And if you have 3000+ files, im sure you can’t rename them all. So the best thing to do i guess is to use a third party app like longpathtool. It can solve issues like this and errors like 1320 in windows 7. i hope this can help.

  31. Frederik Dawin said on February 28, 2013 at 11:12 am
    Reply

    Have you tried using Long Path Tool? I have the same problem as yours and it had been resolved using that tool. Check it.

  32. Sir_Roman_Athens said on July 28, 2013 at 5:47 pm
    Reply

    DO NOT USE THIS “Tool”!!!

    I believe it caused my computer to have repeat BOOTS; Crashing My computer constantly until I was able to correct it (on my own) as my tried-and-true anti-malware software was Unable to detect and remove it!

    I performed the http://www.VirusTotal scan on it. All the engines (except one, Trend Micro) gave it a clean bill of health. TM informed that LPT was actually a T-R-O-J-AN!

    I will stick with my Teracopy from now on.

    S_R_A

  33. adamdee said on August 9, 2013 at 8:20 am
    Reply

    Try and download ” Long Path Tool ” is also useful in situations where you see these error messages: Cannot read from source file or disk, there has been a sharing violation, cannot delete file or folder, the file name you specified is not valid or too long, the source or destination file may be in use and many other file managing errors.

  34. garrydam said on August 26, 2013 at 1:51 pm
    Reply

    With downloading “Long Path Tool” you will be able to fix your long path errors.

  35. Ian C Teig said on November 6, 2013 at 3:28 am
    Reply

    Solution that worked for me:

    Start from the root directory you are attempting to delete, rename every folder going down the tree to a single character, I did the alphabet. By the time I hit M, I was able to delete the contents.

    Hope that helps.

  36. philip said on February 18, 2014 at 2:43 am
    Reply

    Unlocker works fantastic. just when installing it, antivirus will detect a virus and block the virus only, but the rest of program will continue to install. just wait for it.

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

Please note that your comment may not appear immediately after you post it.