Watch out for long path names on an NTFS volume

This content is 20 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.

Comments

66 responses to “Watch out for long path names on an NTFS volume”

  1. jstratton avatar

    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. Sean Duncan avatar
    Sean Duncan

    Thanks, I never thought of renaming the folders either.

  3. Anonymous avatar
    Anonymous

    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.

  4. Allen Garcia avatar
    Allen Garcia

    Brillant Many Thanks Problem Fixed Grate Soultion

  5. doug avatar
    doug

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

  6. Mark avatar

    Don Thompson e-mailed me to let me know that the maximum path length depends on the method of access. It seems that UNC paths can be significantly longer than mapped drive paths.

  7. Sarath Chandra K avatar
    Sarath Chandra K

    Can only repeat. Damn good thinking.
    Too cool. Thanks for the solution, saved a huge effort for me.

  8. Anonymous avatar
    Anonymous

    that link should be http://www.windowsitpro.com/Windows/Articles/ArticleID/44324/pg/2/2.html

    you can paste it in the browser bar in bits!

    helpful

  9. Anonymous avatar
    Anonymous

    Maybe robocopy could be used to generate an error report using the /256 switch, and presumably /ndl /nfl and nocopy switches? You can send the results to a file.

    – worth a try, got the idea here:

    http://www.windowsitpro.com/Windows/Articles/ArticleID/44324/pg/2/2.html

  10. Anonymous avatar
    Anonymous

    There is a downloadable perl solution here, http://www.windowsitpro.com/WindowsScripting/Article/ArticleID/7828/7828.html

    you can specify the threshold of pathname length above which you want a report

    the zip file contains a small readme file but no massive explanantions

    perl can be downloaded http://www.activestate.com (incl msi package)

    helpful

  11. Anonymous avatar
    Anonymous

    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.

  12. Anonymous avatar
    Anonymous

    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?

  13. Anonymous avatar
    Anonymous

    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!

  14. Dus10 D avatar
    Dus10 D

    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.

  15. coki avatar
    coki

    Thanx, it’s really working

  16. Anonymous avatar
    Anonymous

    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.

  17. Anonymous avatar
    Anonymous

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

  18. Anonymous avatar
    Anonymous

    Just wrote this a week or so ago, might help some people:

    http://groups.google.com/group/microsoft.public.windowsxp.general/browse_thread/thread/73cc6a8ca393b91f/167990fdf163250e?lnk=st&q=long+ntfs+path+utility&rnum=2#167990fdf163250e

    feel free to repost any portions if they’re useful

  19. matrixKella avatar
    matrixKella

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

  20. Gregor avatar

    Thanks for the great lead on deleting filenames that are too long. Worked like a charm!

  21. clarv02 avatar
    clarv02

    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!

  22. AlpineSummit avatar

    Sweet resolution!
    good thinking……..

  23.  avatar
    Anonymous

    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.

  24. Patrick avatar
    Patrick

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

  25. Shehan avatar
    Shehan

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

  26. Gabriel avatar
    Gabriel

    Just wanted to leave my thanks as well. This post saved me. Thank you!

  27. Bob Coss avatar
    Bob Coss

    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!

  28. Peter avatar
    Peter

    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.

  29. Kenneth German avatar

    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

  30. Jim Bytheway avatar
    Jim Bytheway

    Many thanks to Bob Coss for a free solution to this problem that actually works =)

  31. n00bf0rc3 avatar

    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

  32. b.rain avatar
    b.rain

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

  33.  avatar
    Anonymous

    great Solution

  34. mark avatar

    @ 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!

  35. Jane avatar
    Jane

    I faced the same problem, it was very useful to use different solutions before but due to Peter’s comment this one appeared to be the best for me http://www.abtollc.com/Products.aspx

  36. Largerick avatar

    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

  37. From Singapore avatar
    From Singapore

    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.

  38. Clair avatar
    Clair

    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

  39. Seth avatar
    Seth

    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

  40.  avatar
    Anonymous

    THAAaaaaaaaaK YOU sOOOOOOOOO MUCH

    Steff

  41. John avatar
    John

    The utility was updated not only to delete but also to copy files avoiding Path Too Long error. http://www.abtollc.com/Folder-Delete.aspx

  42. Mark Wilson avatar

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

  43. Preetha lanka avatar
    Preetha lanka

    Thanks a lot !!! Thanks so muchhh !!!!

  44. Mike avatar
    Mike

    Thanks to Bob Coss.

    Robocopy got me into the mess i was in and it also got me out of it.

  45. Chris avatar
    Chris

    @ COSS… The robocopy solution is awesome! Thanks a million!

  46. bones avatar
    bones

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

  47. […] file structure got too big for Windows to handle so the trick is to shrink the file structure. As Mark Wilson points out you can just rename parent directories to single character names. Do this through a few […]

  48. dan avatar

    This tool can delete/copy/rename long path files/folders
    http://www.longpathtool.com

  49. ammar avatar

    The old URL is for Unix only, the new utility optimized for PC is at: http://www.pathtoolong.com
    ( at least it run correctly for three months on my Windows XP )

  50. Nikola avatar
    Nikola

    I was googling about this problem, and you have solved my problems in a second. Thanks a lot

  51. Sawyer avatar
    Sawyer

    You can mount the path on your PC and change the file names

  52. xavier avatar
    xavier

    I had the same problem and then i sued a software called LongPathtool, it works fine.! i can highly recommend this tool to anyone.

    http://longpathtool.com/Downloads.html

  53. sujeesh avatar
    sujeesh

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

  54. GarryBrown avatar
    GarryBrown

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

  55. garrydam avatar
    garrydam

    With Path too long error I use “Long Path Tool” to get fast and easy fix .

  56. alexias avatar
    alexias

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

  57. FGranados avatar

    You can also use Long Path Tool to sort out this problem.

  58. gregoria avatar
    gregoria

    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.

  59. kevin15 avatar
    kevin15

    Try using Long Path Tool program this is very useful.

  60. Reavio avatar
    Reavio

    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

  61. Kamila Danielo avatar
    Kamila Danielo

    Use Long path tool. It is really awesome one

  62. Markos illona avatar
    Markos illona

    i prefer to use software ( Long Path Tool )

  63. Mark Wilson avatar

    Great to hear that “Long Path Tool” is working for so many people but it wasn’t an option when I wrote this back in 2005. Closing comments now…

  64. […] Finally, I needed to remove the folders that I had accidentally created with recursive Application Data folders inside (I counted 25 in one case!). Neither Windows nor the Windows Command Prompt (del and rmdir commands) could do this, resulting in “too long” errors but Super User Aaron has the answer (which is a variation on the method Bob Coss commented on one of my own old blog posts): […]