Watch out for long path names on an NTFS volume

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.

55 Comments

  • Tuesday 22 November 2005 - 21:47 | Permalink

    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!

  • Sean Duncan
    Wednesday 23 November 2005 - 5:50 | Permalink

    Thanks, I never thought of renaming the folders either.

  • Anonymous
    Friday 25 November 2005 - 8:32 | Permalink

    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.

  • Allen Garcia
    Tuesday 10 January 2006 - 19:57 | Permalink

    Brillant Many Thanks Problem Fixed Grate Soultion

  • doug
    Saturday 14 January 2006 - 21:46 | Permalink

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

  • Monday 23 January 2006 - 16:36 | Permalink

    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.

  • Sarath Chandra K
    Friday 17 February 2006 - 10:13 | Permalink

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

  • Anonymous
    Monday 27 February 2006 - 12:17 | Permalink

    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

  • Anonymous
    Monday 27 February 2006 - 12:14 | Permalink

    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

  • Anonymous
    Tuesday 28 February 2006 - 11:21 | Permalink
  • Anonymous
    Tuesday 28 February 2006 - 12:36 | Permalink

    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

  • Anonymous
    Tuesday 28 February 2006 - 14:42 | Permalink

    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.

  • Anonymous
    Tuesday 28 February 2006 - 14:59 | Permalink

    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?

  • Anonymous
    Saturday 20 May 2006 - 3:56 | Permalink

    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!

  • Dus10 D
    Wednesday 21 June 2006 - 15:09 | Permalink

    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.

  • coki
    Sunday 23 July 2006 - 6:44 | Permalink

    Thanx, it’s really working

  • Anonymous
    Tuesday 19 September 2006 - 12:05 | Permalink

    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.

  • Anonymous
    Monday 4 December 2006 - 7:18 | Permalink

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

  • Anonymous
    Monday 22 January 2007 - 3:54 | Permalink
  • matrixKella
    Monday 14 May 2007 - 3:20 | Permalink

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

  • Thursday 24 May 2007 - 19:45 | Permalink

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

  • clarv02
    Saturday 9 June 2007 - 23:07 | Permalink

    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!

  • Wednesday 1 August 2007 - 21:06 | Permalink

    Sweet resolution!
    good thinking……..

  • Anonymous
    Monday 13 August 2007 - 16:47 | Permalink

    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.

  • Patrick
    Sunday 26 August 2007 - 20:22 | Permalink

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

  • Shehan
    Saturday 6 October 2007 - 13:11 | Permalink

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

  • Gabriel
    Thursday 13 December 2007 - 22:49 | Permalink

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

  • Bob Coss
    Wednesday 23 January 2008 - 14:07 | Permalink

    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!

  • Peter
    Monday 28 January 2008 - 12:28 | Permalink

    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.

  • Wednesday 6 February 2008 - 9:35 | Permalink

    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

  • Wednesday 6 February 2008 - 18:36 | Permalink
  • Jim Bytheway
    Tuesday 6 May 2008 - 15:54 | Permalink

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

  • Sunday 8 June 2008 - 14:23 | Permalink

    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

  • b.rain
    Sunday 29 June 2008 - 9:42 | Permalink

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

  • Anonymous
    Wednesday 2 July 2008 - 12:27 | Permalink

    great Solution

  • Thursday 14 August 2008 - 17:07 | Permalink

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

  • Jane
    Monday 8 September 2008 - 6:53 | Permalink

    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

  • Monday 22 September 2008 - 16:08 | Permalink

    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

  • From Singapore
    Tuesday 21 October 2008 - 10:02 | Permalink

    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.

  • Clair
    Monday 3 November 2008 - 12:29 | Permalink

    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

  • Seth
    Wednesday 12 November 2008 - 6:15 | Permalink

    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

  • Anonymous
    Friday 16 January 2009 - 19:31 | Permalink

    THAAaaaaaaaaK YOU sOOOOOOOOO MUCH

    Steff

  • John
    Saturday 17 January 2009 - 10:30 | Permalink

    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

  • Wednesday 28 January 2009 - 22:37 | Permalink

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

  • Preetha lanka
    Thursday 29 January 2009 - 0:53 | Permalink

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

  • Mike
    Thursday 21 May 2009 - 17:17 | Permalink

    Thanks to Bob Coss.

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

  • Chris
    Friday 17 July 2009 - 2:04 | Permalink

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

  • bones
    Thursday 1 October 2009 - 12:24 | Permalink

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

  • Pingback: Deleting files with names that are too long

  • Saturday 23 October 2010 - 21:06 | Permalink

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

  • Thursday 18 November 2010 - 17:14 | Permalink

    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 )

  • Nikola
    Wednesday 16 March 2011 - 22:26 | Permalink

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

  • Sawyer
    Wednesday 30 November 2011 - 21:05 | Permalink

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

  • xavier
    Thursday 15 March 2012 - 14:18 | Permalink

    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

  • sujeesh
    Friday 18 May 2012 - 7:21 | Permalink

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

  • Leave a Reply

    Your email address will not be published.

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>