ghacks Technology 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.

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?

Enjoyed the article?: Then sign-up for our free newsletter or RSS feed to kick off your day with the latest technology news and tips, or share the article with your friends and contacts on Facebook or Twitter.

Related Articles:

Edit Environment Variables and find invalid ones
Uncover File Manipulations With File Checksum Integrity Verifier [Windows]
How to delete “cannot delete files”
Securely delete files with secure-delete
ExtMan, Create, Edit, Delete File Extensions In Windows



About the Author:Martin Brinkmann is a journalist from Germany who founded Ghacks Technology News Back in 2005. He is passionate about all things tech and knows the Internet and computers like the back of his hand. You can follow Martin on Facebook or Twitter.

Author: , Sunday August 15, 2010 -
Tags:, , , , ,


Responses so far:

  1. Mehdi S says:

    unlocker ftw…

  2. FL says:

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

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

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

  5. paul(us) says:

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

  6. Mike says:

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

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

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

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

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

  11. frank says:

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

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

  13. Transcontinental says:

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

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

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

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

    I like the solution at this site :)

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

  18. damfiles says:

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

    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!

    • Diego says:

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

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

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

    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.

  22. Baba says:

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

Leave a Reply   Follow Ghacks   Subscribe To Comment Rss

Subscribe without commenting

© 2005-2012 Ghacks.net. All Rights Reserved. Privacy Policy - About Us