This project is read-only.


DotNetZip should be kinder when throwing PathTooLongException


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


VanessaBR wrote Feb 27, 2012 at 7: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 2: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)?


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:

GabrielNar89 wrote Nov 19, 2012 at 2: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.
Long Path Tool can simplify and probably end your problems in unlocking, managing and renaming files that appear to have a long filename.

wrote Feb 22, 2013 at 2:43 AM

wrote May 16, 2013 at 1:31 PM

franklo wrote Jun 20, 2013 at 3:05 PM

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