Watch out for long path names on an NTFS volume

This content is 18 years old. I don't routinely update old blog posts as they are only intended to represent a view at a particular point in time. Please be warned that the information here may be out of date.

I came across an interesting issue earlier today. Somehow, on my NTFS-formatted external hard disk I had managed to create a file system structure which was too deep.

Whenever I tried to delete a particular folder tree, I received strange errors about files which couldn’t be deleted:

Error Deleting File or Folder

Cannot delete foldername: The file name you specified is not valid or too long. Specify a different file name.

I thought that was strange – after all, I’d managed to create the files in the first place, then I found that if I drilled down to the files that would not delete, there was no right-click option to delete the file. Finally, I found that some folders displayed the following error when I tried to access them:

Can’t access this folder.

Path is too long.

It turned out that the problem folders/files had path names in excess of 255 characters. By renaming some of the top level folders to single character folder names (thus reducing the length of the path), I was able to access the problem files and folders, including deleting the files that I wanted to remove.

66 thoughts on “Watch out for long path names on an NTFS volume

  1. Damn good thinking! I never thought to rename the folders (my first inclination was to use DSL (Damn Small Linux), but your solution keeps me in Gate’s reach.

    Thanks!

  2. There should be some shareware somewhere that will seek this out and let you fix it in advance. As said, maddening because you could create the path in the first place. I’d love to know all the paths on my hard drive which are ‘too long’ in advance. I think modern Windows conventions where “My Documents” is buried deep within other folders (c:\files and documents\users\admin\etc\etc\my documents) contributes to this.

  3. Brilliant, I had the same problem, eventually reformatted the external ntfs hard drive!! … and then read your solution after :~(

  4. I just used the 7828.pl file zipped in the download mentioned above:
    works fine. I just opened the .pl file with a text editor and put my own paths in – it’s explained by the author anyway inside th .pl file.

    My longest path was 231 characters and likely to expand (you know how it happens, someone creates a folder “fotherington-smythe’s archive sent by e-mail to Thomas, Thomas and Thomas on 30 February 2006”).
    Now every path is back under 200 characters, and users have been alerted to what I only estimated previously.

  5. p.s. Won’t robocopy copy everything anyway? Or move it with the /mov switch, or delete it by copying an empty folder to the top location of the part of the tree you want to erase and you using the /purge switch – you will then get a list of “extra” files and folders deleted below that location. or use the /mov switch to the NUL directory to delete stuff (I never got that one to work yet, but I have seen claims it does – i have no idea about syntax).

    This is my lunchtime backup
    AT 13:00 /every:M,T,W,Th,F C:\WINDOWS\system32\robocopy.exe \\server\share\ c:\backup\ /xf *.tmp /xf ~$*.* /s /e /zb /purge /nfl /ndl /log:c:\Logs\lunchtime.txt

    it synchs a day’s work in minutes – I run it to a different network hard-drive each day to keep a weeks backups “right there”, uses hardly any bandwidth. I probably don’t need the /zb switch.

    Helpful?

  6. I had this exact problem while trying to back up files onto my Maxtor External hard drive. I was puzzled until today. I found a great app on Download.com called File and MP3 Renamer 2005
    http://www.download.com/File-and-MP3-Renamer-2005/3000-2248_4-10482097.html?tag=lst-4-3

    It lets you trim file names by a certain # of characters, or to a maximum length. And it can do them from the left or right side of the file name. It has many more ways of changing file names than that but I just went for the basic right-side file name trim.

    The only thing it can’t do is find all files whose path names exceeds a certain length. Also, while the app can do hundreds or thousands of files at a time by trimming all files in a folder and its sub-folders, it does tend to crash if you do too many. So I couldn’t do my entire MyDocuments folder and all subfolders at once.

    The only other quibble I would have is the interface is a bit unclear, namely that the buttons might say “Do this folder” and you might think that pressing it will choose that option, when in fact it then selects the OTHER option, that is, “Do this and all sub-folders at once”.

    But it’s free for a 10-day trial and works great. I’m backing up my files right now with Retrospect without getting that uber-annoying “path name too long” message!

  7. Thanks for that advise. Somehow, a seemingly endless nested directory structure was created of directories named “2003”. I am unsure how it even allows them to be created in the first place. My guess is that when files/directories are created, their blocks are allocated first, and then their name is placed in the file header, and then it is placed in its path within the filesystem. That seems like a possibility, at least.

  8. If you wish to avoid renaming folders (currently in use or you’re afraid of getting them back correctly), you can share a folder along the path and map that folder as a “remote” drive and then delete the file via the mapped drive letter path. Remember to remove sharing afterwards.

  9. Wonderful, thanks for that. Took your advice and it solved my problem.

    I had a script go wrong on me resulting in folders within folders within folders, etc.

    After renaming the folders to single character names, I was able to dive deeper and deeper, ending up 71 folders deep. Most importantly, I was able to delete the string of empty and useless folders!

    Thanks again. :-)

  10. Thanks greatly , this info solved me problem within a few file renames. CHAMP! Your info is great.

  11. Brilliant, indeed! My original source parent folder was quite long, so I renamed that. Then I also realized that the target folder on the new server was named VERY long, without thinking about the long filename restrictions. So I also renamed that target folder to a single word. All data copied over just fine.

    Thanks!

  12. The foolowing 2 free tools may be of some use “to know all the paths on my hard drive which are ‘too long’ in advance” as suggested by post nr 3 in this thread:
    =====
    1)
    =====
    Long Filename Finder looks for file name length: http://www.dcsoft.com/products.htm
    http://www.dcsoft.com/products.htm
    =====
    2)
    =====

    Even better: CutLongNames (http://www.replsoft.com/)

    http://www.replsoft.com/cutlongnames.zip

    This one allow you to search for total path plus filename lenght above a given value

    Would need some improvement though:
    – files with path lenght over 222 (excluding the file name) are displayed in red, and not clear why this threshold has been choosen (does not mach the OS limitaion)
    – no progress bar while scanning (however I used It on a local HD 4 Gb folder in a few seconds)
    – You need to press Edit button to see the detail of the path length and the filename length
    – its quite easy to mix up between the search phase and the renaming phase (because the same button in used for both functions) ans I’m not very confident in the mass renaming function which has no undo feature (although there is a log in case you want to undo manually by yourself)

    If someone around can find better, please post here.

  13. I had the same issue. Yet the renaming technique didn’t work as the name was really long. Eventually I found the solution at http://winhlp.com/?q=node/39 “Cannot delete file or folder | Windows Problem Solver”

    What worked for me was to use the DOS name, which is limited to 8+3 characters :

    1. opening a command promt window,
    2. finding the DOS name with DIR /X,
    3. removing the folder using the RMDIR command followed by the DOS name.

    HTH:)

  14. Superb I had the Same Problem thanks to you I did not have to format my hard drive.Which was what I was going to do before I found this solution. Thank You ,Thank You , Thank You Very Much !!.

  15. I used the advice of a writer above and got a copy of robocopy. I deleted the directory by using the syntax: robocopy dummydirectory bad_directory /E /NOCOPY /PURGE . The dummydirectory was a temporary subdirectory that I created that had one small file in it. ROBOCOPY deleted thousands of subdirectories that had been created by a rogue program that was recursively creating new subdirectires.

    It was the only probram or tool that could delete them as deep as they were. THANKS!

  16. I’ve been using the following library that resolves the long filename & path issue. It is not free, but comes with samples and working code. It saved so much of my time!

    http://www.abtollc.com/product1733992.html

    There is no need to rename files or perform any other actions, it just allows to work with files keeping their real long paths, thats all.

  17. Hey There

    I had the same problem, had some users that should have moved their data files to some new servers.. but I couldn’t copy all the files because of long filenames..
    I have just found a fine solution, that works.
    To create a 100% copy of all the files, the users get the file as they have it now.. Use ntbackup, create a backup, move the backup file to the new server, and then restore the data to an alternate location, and thats it.
    Worked for me :)

    /kenneth

  18. Thanks a lot. I’ve been trying to delete a folder for about a month now. I used unlockers and everything. Didn’t know it was that easy. Thanks

  19. Thanks!
    After 3 days voo-doo-witchdoctoring-cmd-prompting and Googling tis was the solution… Thanx! You are my Guru!

  20. @ BOB COSS
    Excelent advice on the robocopy command. I ran into this issue when using robocopy for file server backups/replication. The original file wasn’t too long, but the moved file was (longer folder path). I added that brilliant use of robocopy to my vbscript and now we have no issues programmatically deleting long file paths!!

    Furthermore, I also have been struggling to find easy ways to delete systems files and files/folders that have been given very rescrictive permissions (1 user only and such). That command also works to remove files/folders you don’t have access to (I think system must have access – not real sure on that).

    Thanks again to Bob for the command and to Mark for the site!

  21. Thanks so very much, Mark. Using your advice, I highlighted all of the files that wouldn’t delete. Then I renamed them all at once, using the letter a. Your suggestion worked like a charm. Thanks again; Largerick

  22. Thanks alot for your idea. I have been trying it for few days and other advices found on internet are not as simple and brilliant as yours.

  23. Hi, been reading this and it all seems very useful, but I am searching for long filenames on a citrix system. I’ve asked my IT dept to do this, but they cannot seem to so I thought I’d just research the net myself.

    Can I ask which one of the tools/options mentioned in this forum is the best for just searching filenames that exceed the 255 length. I want to search what is known as our s: drive but don’t want to automatically rename stuff.

    Thanks for your help on this

  24. Thank you…thank you…thank you! So simple. I’d been going nuts trying to figure out what the issue was with some of my files. This saved me a LOT of work. Many thanks again!

    Seth

  25. Interestingly, a similar issue came up on the Windows 7 beta forums where Gordon Ryan made an interesting post:

    “The root cause for this appears to be a variable known as MAX_PATH and the programs that use it.

    So for NTFS, the specifications allow for path lengths of up to 32767. The issue then arises as a result of applications and how they are written and interact.

    There is a very good KBarticle, 320081, that goes through a number of scenarios dealing with long file names and paths that might be worth a look for reference for you.”

  26. To All: I have been trying for 6 months to delete a file name “ZB” that came with a Canon software disk. You all gave me an answer. The renaming was what I needed, but Robocopy is a permanent addition to my collection. Thank you, ALL!.

  27. for solving this issue there is one simple method available please follow
    1- please drag and drop the Folder that you wish to delete to a new folder or
    C:\RECYCLER
    2.then press shift+delete or normal delete
    it should work …………….

  28. Thanks for the information. Also try “Long Path Tool”. It helped me with Error 1320 in Win 7.:)

  29. for All errors while these processes has been taken care by software named “DuplicateFilesDeleter”

  30. I am using a software called Long Path Tool and it is working like charm, i have no problems in copying or extracting anything anywhere.

  31. for solving this issue there is one simple method available please follow
    1- please drag and drop the Folder that you wish to delete to a new folder or
    C:\RECYCLER

Comments are closed.