When attempting to add the folder to the archive, the path is too long
-
Using .Net Framework 4.0; VS 2015; Ionic.Zip.Reduced (DotNetZip.Reduced) v1.9.1.8. When attempting to add a folder to the archive, the archive is exempted from the text:
The path is too long
Example of code:
using (var zipFile = new ZipFile(zipFilePath)) { zipFile.UseZip64WhenSaving = Zip64Option.AsNecessary; zipFile.AlternateEncodingUsage = ZipOption.Always; zipFile.AlternateEncoding = Encoding.UTF8; zipFile.ParallelDeflateThreshold = -1;
var dirPath = @"C:\AAAAAAAAAAA\AAAAAA\AAAAAAAAAAAAAAA\AAAAAAAAA\AAAAAAAAAAAAA\AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
zipFile.AddDirectory(dirPath); <-Exception
zipFile.Save();
}
The file contains a file with the name:
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.zip
As a result of performance, error:
The path is too long
Transferred to the postage in the archives (using the relative route):
using (var zipFile = new ZipFile(zipFilePath))
{
zipFile.UseZip64WhenSaving = Zip64Option.AsNecessary;
zipFile.AlternateEncodingUsage = ZipOption.Always;
zipFile.AlternateEncoding = Encoding.UTF8;
zipFile.ParallelDeflateThreshold = -1;var dirPath = @"C:\AAAAAAAAAAA\AAAAAA\AAAAAAAAAAAAAAA\AAAAAAAAA\AAAAAAAAAAAAA\AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
Directory.SetCurrentDirectory(dirPath);
var files = Directory.GetFiles(dirPath, "*", SearchOption.AllDirectories).ToArray();foreach (var fullFilePath in files)
{
var fileName = Path.GetFileName(fullFilePath);
var relatedPath = fullFilePath.Substring(0, fullFilePath.LastIndexOf(fileName, StringComparison.InvariantCultureIgnoreCase)).Replace(zipDir, "");
var relatedFilePath = Path.Combine(relatedPath, fileName);zipFile.AddFile(relatedFilePath); <-Exception
}
zipFile.Save();
}
Wrong mistake:
The path is too long
I tried to call a method.
Path.GetDirectoryName()
But he's making a mistake, too: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.I've found a lot of solutions but it's never worked out to make it work.
- Use Framework 4.6.2. Set https://blogs.msdn.microsoft.com/jeremykuhne/2016/06/09/new-net-path-handling-sneak-peek/
UseLegacyPathHandling=false
TotalApp.Config
or evenSwitch.System.IO.UseLegacyPathHandling=false; Switch.System.IO.BlockLongPaths=false
- Some reference is made to the group policy and the inclusion of the Configuration derivative Templates stat System der Filesystem vent. https://msdn.microsoft.com/library/windows/desktop/aa365247.aspx#namespaces , or insert the opaque with a manifest
<ws2:longPathAware>true</ws2:longPathAware>
- Use the prefix
\?</code> https://msdn.microsoft.com/library/windows/desktop/aa365247.aspx#maxpath (I realized I was also on the new version of the Framework."
- Transform the way to the file into 8.3 by function https://msdn.microsoft.com/en-us/library/aa365247(v=vs.85).aspx ....
Maybe someone had a problem like that. I'll be happy with any advice.
- Use Framework 4.6.2. Set https://blogs.msdn.microsoft.com/jeremykuhne/2016/06/09/new-net-path-handling-sneak-peek/
-
It's the problem of the operating system itself, it's been fixed just the other day for windows 10 in another pd.
Read this article on the Habre: https://habrahabr.ru/post/307186/ - In principle, there's a good summary of the options you mentioned.
Использовать Framework 4.6.2
- This is not a good option. Not don't everyone have that kind ofimvor, what do we do on other operatives?Использовать префикс \\?\
- there will be the same mistakes unless there is support for long paths. Yeah, just a new Framworth, alas.The simplest option is to send a message to the user that the operating system does not support such long paths, to suggest a redesign of the catalogue structure and/or to reduce the name of the files.
Why don't you just catch an exception and work it out honestly? Even if you find a temporary folder where one specific name fits, there'll be three more symbols tomorrow longer and again.