1

Closed

DotNetZip should be kinder when throwing PathTooLongException

description

from http://dotnetzip.codeplex.com/discussions/267600
 
I encountered the System.IO.PathTooLongException, using ZipFile.AddDirectory() to save a zip. Problem here, the resulting exception doesn't even say which path was too long . Using the DotNetZip devkit I saw this happened in ZipEntry.Create when File (Directory) will be first accessed with File.GetLastWriteTime(filename) (ZipEntry.cs line 2402).
 
The path really was too long. A subdirectory of the directory I wanted to zip had a path longer than 259 characters (267 :) ), apparently the maximum path length the .NET IO system can handle. So the error was due to the .net limit. I found a nice blog post about this and how to use Win32 to access file/folders with >260 path length. http://blogs.msdn.com/b/bclteam/archive/2007/02/13/long-paths-in-net-part-1-of-3-kim-hamilton.aspx
 
If you zip such a directory, the whole process fails. What really bothered me was to find out which file/directory was too long, because the PathTooLongException doesn't return the path value. So it would be nice if you would catch this PathTooLongException and return a custom exception that tells u the path.
Closed Aug 6, 2011 at 10:12 PM by Cheeso
Fixed in changeset 81671. The new behavior is to catch a PathTooLongException, then create and throw a new ZipException that specifies the offending path, passing the PTLE as an inner exception. The first binary that will have this change available will be v1.9.1.8

comments

VanessaBR wrote Feb 27, 2012 at 6:04 PM

I tried this, but I still can't get the long path. Can you explain better? Tks.

G1 wrote Aug 9, 2012 at 1:36 PM

I am curious at to why the "too long" file name was not simply included in the message of the Path Too Long Exception (PTLE)?

E.g.

The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters:
[C:\dfljls\sdf\sdf\d\fs\dfsfsfsdfad\jfsdkljfljadjk.jfkd]

GabrielNar89 wrote Nov 19, 2012 at 1:56 PM

This is a Windows* OS/file system issue.The cause is directory paths on the drive is longer than 255 characters (including spaces).There's a lot of additional softwares which can fix this problem like Long Path Tool.
http://PathTooDeep.com
Long Path Tool can simplify and probably end your problems in unlocking, managing and renaming files that appear to have a long filename.

franklo wrote Jun 20, 2013 at 2:05 PM

Long path tool is the best solution for your problem. try it and solve your problem.