none
Cannot delete file: filename too long

    Question

  • Sometime ago, I made a copy of a hierarchy of folders under my "Users" folder to another drive as a quick backup. I no longer need this copy of folders and files. So when I tried to delete these files I got a message that some filenames are too long. When I look at these files they mostly seem to be part of Internet Explorer temp directory, and also some files used by Mozilla Thunderbird, so they were likely created by these utilities on purpose. I cannot rename them to shorter names, or even move them to lower folders. I can't even copy their filenames to show you what these filenames are! When I use the DOS prompt's "dir /x" command these files do not even have any 8.3 short filenames either, which I could've used to delete them with. There are over 400 of these files!

    I know what the problem is, the Windows OS has a limit of somewhere around 250 characters for filenames and complete pathnames. I've seen some utilities advertised saying that they can delete these files, but they all require money. Anything that's free?


    Yousuf Khan
    Saturday, May 14, 2011 4:45 AM

Answers

  • Looks like no one has an answer to this one. Well I tried something really desperate yesterday. I decided to boot into Linux and mount this Windows disk under it. That did the trick, all I had to do is mount the disk, and then navigate to the folder hierarchy which I wanted removed. Just right-click it in the Linux file explorer, and tell it to delete. It took a split second and it was gone. It was in fact faster than when I tried deleting it under Windows, because under Windows it seemed to go and find each individual file and delete each one. In Linux, it simply deleted the base folder and everything was gone underneath.

    Yousuf Khan
    • Marked as answer by yjkhan Saturday, May 14, 2011 8:47 PM
    Saturday, May 14, 2011 8:47 PM

All replies

  • Looks like no one has an answer to this one. Well I tried something really desperate yesterday. I decided to boot into Linux and mount this Windows disk under it. That did the trick, all I had to do is mount the disk, and then navigate to the folder hierarchy which I wanted removed. Just right-click it in the Linux file explorer, and tell it to delete. It took a split second and it was gone. It was in fact faster than when I tried deleting it under Windows, because under Windows it seemed to go and find each individual file and delete each one. In Linux, it simply deleted the base folder and everything was gone underneath.

    Yousuf Khan
    • Marked as answer by yjkhan Saturday, May 14, 2011 8:47 PM
    Saturday, May 14, 2011 8:47 PM
  • Hi,

    How about holding Shift + Delete?

    Google for MoveOnBoot. MoveOnBoot will only removes files and not directories though.

    Best Regards,
    L.S

    Tuesday, May 17, 2011 3:31 AM
  • Hi,

    How about holding Shift + Delete?

    Google for MoveOnBoot. MoveOnBoot will only removes files and not directories though.

    Best Regards,
    L.S

    Why is shift-delete different?

    Yousuf Khan
    Tuesday, May 17, 2011 4:51 AM
  • Hi,

    It is just for testing. It is good since the files can be deleted in Linux.

    However, if you don't have Linux, it needs to find the way to delete the files under Windows.

    Since the files are located in Internet Explorer temp directory, you could use Disk Cleanup to clear the Temporary Internet Files.

    Also, check if the following KB is helpful. It has several methods. Go to check if 8.3 name creation is disabled.

    http://support.microsoft.com/default.aspx?scid=kb;en-us;320081

    Best Regards,
    L.S

     


    Tuesday, May 17, 2011 10:02 AM
  • Hi,

    It is just for testing. It is good since the files can be deleted in Linux.

    However, if you don't have Linux, it needs to find the way to delete the files under Windows.

    Since the files are located in Internet Explorer temp directory, you could use Disk Cleanup to clear the Temporary Internet Files.

    Also, check if the following KB is helpful. It has several methods. Go to check if 8.3 name creation is disabled.

    http://support.microsoft.com/default.aspx?scid=kb;en-us;320081

    Best Regards,
    L.S

    Regarding it being in the Internet Explorer temp directory, it actually wasn't. Remember I said in the original posting that this was in a backup directory of these directories, so Disk Cleanup has no way of knowing that this belongs to Internet Explorer or anything else. Also there was a Thunderbird directory having the same issues as well, which Disk Cleanup wouldn't have touched no matter what.

    Okay, I checked out the state of the filesystem registry. The "NtfsDisable8dot3NameCreation" entry in the "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem" is set to non-zero, meaning the feature is in effect. Interestingly it was set to 2 rather than 1, but I doubt that makes a difference.

    Even if I disable this feature right now, all previously created files still won't be assigned the 8.3 filenames, just only those files that are newly created will have the 8.3 filenames available.


    Yousuf Khan
    Thursday, May 19, 2011 12:57 AM
  • I had a similar problem with file name "too long" on Win XP.

    With code that walked through every directory tree and making changes to each file and the new saved to a different location.  All was fine until a saved location was specified as sub directory under the source directory.

    It recursively made empty sub directories, ~2800.

    After searching for several hours and trying everything mentioned could not delete them.

    Even after opening the dual boot to Ubuntu 11.04 and accessing that directory under "host" it could not delete the directory.

    I had to write some code to walk the directory and after so many then rename the next which "moved" all subsequent subs, which didn't actually move anything on the hard drive but just the index of where it is at, like the FAT table or however that is done in NTSF.

    Then the few that were left in the source directory could be deleted.

    I had to tinker with the number left so it was not "too long" and throw the same error.

    That had to be done over and over until they could all be deleted.

     

     

     


    Thursday, June 16, 2011 11:55 AM
  • I would have tried to emacs the directory and pressed 'd' and I think 'x' to expunge.  Or use the cygwin unix commands for windows.

     

    Thursday, June 16, 2011 5:55 PM
  • For future reference, the trick is to substitute a drive letter for the parent path, thus making the total path less than the 250-odd character limit.

    e.g.

    For file in "C:\a\very\long\path\You cannot delete me.txt" do:

    subst x: "C:\a\very\long\path"
    del "x:You cannot delete me.txt"
    subst x: /d

    There is a Microsoft KB article about deleting stubborn files, which suggests adding the Windows internal path prefix of "\\?\" to the path (e.g. "\\?\c:\a\very\long\path") which has no limit, but unfortunately doesn't work at the command line.

    The path prefix is commonly used by device drivers internally to register their devices' physical path or to reference drive letter agnostic paths, e.g. with the volume GUID at the start instead of a letter. It has been supported in every version of Windows since Windows NT. I know that because I wrote a File System service driver compatible with NT and 2000 some twelve years ago now 8-)

    • Proposed as answer by indrawn Friday, July 05, 2013 2:45 AM
    Monday, May 21, 2012 1:04 AM
  • You probably cannot rename the last file because it's path is teh end of the string that is too long, but you should be able to rename the folders in between, starting at the root. Once renamed, you will shorten the whole path length, and you will be able to delete the folder tree.


    Geoff Courts, Operations Manager, Macnamara IT www.macnamara.it

    • Proposed as answer by Dane A Morgan Friday, November 09, 2012 12:21 PM
    Tuesday, May 29, 2012 8:17 AM
  • I just had this same problem but I don't have Linux to fall back on.

    My (simple) solution was to use a command prompt and the Del command in conjunction with the /s (subfolders) option. It deleted the files that were the cause of the problem and I was then able to delete the parent folders via Explorer.

    Sample from command prompt:

    del x:\Dir\Subdir1\*.* /s

    I hope this helps!

    -Eric

    • Proposed as answer by Eric_EM Friday, June 15, 2012 5:20 PM
    Friday, June 15, 2012 5:19 PM
  • I use "Long Path Tool" in this situation and it helps me well.
    Thursday, October 04, 2012 3:44 PM
  • Use 'RoboCopy' to mirror (/mir) an empty folder (that you create) in to the directory that you wish to delete. Reference: http://superuser.com/a/296241/56505
    Monday, October 22, 2012 4:58 PM
  • Dear friend,

    Try this command...

    Via command-Prompt go to directory where is there the requested file and type: > del /Q "filename"
    Ex.

    C:\Documents and Settings\User\Desktop\ > dir

    > del /Q "testfile.txt"

    Tuesday, October 23, 2012 2:13 PM
  • Dear friend,

    Try this command...

    Via command-Prompt go to directory where is there the requested file and type: > del /Q "filename"
    Ex.

    C:\Documents and Settings\User\Desktop\ > dir

    > del /Q "testfile.txt"

    Code Chief answered this question competently some 18 months ago. Your answer does not add anything useful to his solution because it does not work.
    Tuesday, October 23, 2012 2:36 PM
  • Another option is to create a junction using Junction Link Magic or NTFS Link (or the command line). This is rather like subst, but better - you can create a folder C:\x which is just a hardlink to, say, C:\Areallylongfoldernameindeed. This may shorten the total path enough to allow you to manipulate the file.
    Tuesday, December 04, 2012 11:26 PM
  • I have downloaded Long Path Tool and it helped me a lot .
    Friday, January 18, 2013 2:46 PM
  • Absolute genius Geoff! This is the simplest and easiest way to fix the problem. I started at the top directory and moved down through each folder renaming them all to ‘1”. If it ever asked if I wanted to merge folder also named 1, I just said yes. Thanks again! I was getting worried at first having read all the ideas on installing software writing code, etc… You thought out of the box and came up with the easy fix.

    Friday, February 22, 2013 4:32 PM
  • Thanks :) Simple solutions always win

    Geoff Courts, Operations Manager, Macnamara ICT www.macnamara-ictt

    Friday, February 22, 2013 4:34 PM
  • Absolute genius Geoff! This is the simplest and easiest way to fix the problem. I started at the top directory and moved down through each folder renaming them all to ‘1”. If it ever asked if I wanted to merge folder also named 1, I just said yes.

    Thanks again! I was getting worried at first having read all the ideas on installing software writing code, etc… You thought out of the box and came up with the easy fix.
    • Proposed as answer by I.M.Lance Friday, February 22, 2013 4:36 PM
    Friday, February 22, 2013 4:35 PM
  • Thank you geffcourts!!! Been trying to delete a file for some time now.
    Saturday, May 04, 2013 8:49 PM
  • I just had the same problem. Deleted the file in this way:

    1. open a command prompt as admin
    2. cd "my folder"
    3. dir /X "undeleteable looooooong filename"
    4. copy the short filename
    5. del "shortname"

    This worked!


    Advizor Hosting, Microsoft Partner

    Friday, May 10, 2013 12:37 PM
  • I faced the same problem when trying to delete one of my friends folder from my d drive. First try to rename the parent folder(better if you rename it with a single letter) which contains all the sub folders or files, then rename the folder inside it.

    For example: consider the below path

    D:\XYZ Backup\TBD\xasgxuywgqsgbwkjs\dkwgdiuwehkjnckh\xjhsagdcgaskb\jkasgbsbb...............

     

    1. Rename "XYZ Backup" as x

    2. Next rename "TBD" as t..........

     

    Do the same till you reach the last file/folder in it. Then try deleting it.

     

    Hope this will work.

    Tuesday, June 18, 2013 5:51 AM
  • Brilliant. I just had this problem, and using subst solved it. Thank you.
    Friday, July 05, 2013 2:46 AM
  • I just had this same problem but I don't have Linux to fall back on.

    My (simple) solution was to use a command prompt and the Del command in conjunction with the /s (subfolders) option. It deleted the files that were the cause of the problem and I was then able to delete the parent folders via Explorer.

    Sample from command prompt:

    del x:\Dir\Subdir1\*.* /s

    I hope this helps!

    -Eric

    Thanks a lot for this solution, it worked for me!
    Wednesday, September 18, 2013 12:46 PM
  • BRILLIANT SOLUTION!

    I have been reading a lot of solutions that either do not work or are too complicated. Yours is elegant, easy enough for anyone to implement, takes very little time and it works!

    Thank you for your insight.

    /s/ Alan Auerbach

    Friday, September 20, 2013 11:12 PM
  • Try Long Path tool it's worth your money...
    Monday, November 04, 2013 1:20 AM
  • Yet another answer: you can use the Far Manager (http://farmanager.com) - Norton Commander alike software for Windows from authors of WinRAR. Well, in case you don't know what FAR is. Works like a charm.
    Friday, January 03, 2014 10:23 AM
  • Command prompt works!

    Saturday, March 29, 2014 3:22 PM
  • Use 'RoboCopy' to mirror (/mir) an empty folder (that you create) in to the directory that you wish to delete. Reference: http://superuser.com/a/296241/56505
    This is the best solution! -- All other solutions required a lot of manual work.  This solution automatically parses through the entire directory structure with 1 simple command.   At least this is what I needed for my command line backup routines.  And it's free!
    Sunday, May 25, 2014 1:44 AM