Reputation: 16939
I am extracting a zip file like this
ZipFile.ExtractToDirectory(zipFile, extractTo);
But I am getting a
{"Could not find a part of the path 'C:\\....many subfolders\\Extremely long filename'."}
The zip file contains a file with a very long path and filename c.a. 280 chars in total. I am not sure if that is the problem I enabled long path as demonstrated here https://blogs.msdn.microsoft.com/jeremykuhne/2016/07/30/net-4-6-2-and-long-paths-on-windows-10/
If I open the path in explorer it opens but the file with the long filename is not there. If I open the zip file the file is there so there seems to be a problem extracting file with long filename.
Is it possible to skip a file during the zip extraction or allowing extracting files with long filenames?
Upvotes: 6
Views: 3329
Reputation: 3935
If you are using a Windows based file system, the maximum length of a filename is 255 characters. Note: the folder path is included in the file name when calculating the file name length. If you have a long folder path, then you might want to try extracting to c:\temp, which is only using 7 characters. Thus leaving you with 248 characters to work with. If you have file names longer than that within your archive, you might want to address that issue first that way your not having to exclude files from extract.
https://msdn.microsoft.com/en-us/library/windows/desktop/ee681827(v=vs.85).aspx
http://www.ntfs.com/ntfs_vs_fat.htm
Maximum filename length in NTFS (Windows XP and Windows Vista)?
Upvotes: 1
Reputation: 11963
using (ZipArchive archive = ZipFile.OpenRead(zipPath))
{
foreach (ZipArchiveEntry entry in archive.Entries)
{
if (entry.FullName.Length > 280)
continue;
entry.ExtractToFile(Path.Combine("your path", entry.FullName));
}
}
ZipFile.OpenRead
will allow you to inspect the content of the zip file. Then you can enumerate thru the .Entries
property to find out all the files inside the archive and decide if you want to proceed with extract based on the file name length .
Upvotes: 2