Pages

Sunday, July 23, 2006

Watch out for long path names on an NTFS volume From MarkWilson_co_uk

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.

Posted @ 22:28 (Permanent link)
View/add comments (15 comments added previously) | Backlinks | E-mail this post to someone

Comments
Posted by jstratton @ 22 November, 2005 21:47:
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!


Posted by Sean Duncan @ 23 November, 2005 05:50:
Thanks, I never thought of renaming the folders either.


Posted by Anonymous @ 25 November, 2005 08:32:
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.


Posted by Allen Garcia @ 10 January, 2006 19:57:
Brillant Many Thanks Problem Fixed Grate Soultion


Posted by doug @ 14 January, 2006 21:46:
Brilliant, I had the same problem, eventually reformatted the external ntfs hard drive!! ... and then read your solution after :~(


Posted by Mark @ 23 January, 2006 16:36:
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.


Posted by Sarath Chandra K @ 17 February, 2006 10:13:
Can only repeat. Damn good thinking.
Too cool. Thanks for the solution, saved a huge effort for me.


Posted by Anonymous @ 27 February, 2006 12:14:
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


Posted by Anonymous @ 27 February, 2006 12:17:
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


Posted by Anonymous @ 28 February, 2006 11:21:
furthermore http://www.langa.com/newsletters
/2005/2005-08-25.htm

has an item, and links to

http://www.herve-thouzard.com/modules
/wfsection/article.php?articleid=1

helpful


Posted by Anonymous @ 28 February, 2006 12:36:
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 www.activestate.com (incl msi package)

helpful


Posted by Anonymous @ 28 February, 2006 14:42:
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.


Posted by Anonymous @ 28 February, 2006 14:59:
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?


Posted by Anonymous @ 20 May, 2006 03:56:
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!


Posted by Dus10 D @ 21 June, 2006 15:09:
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.

No comments: