1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
using (ZipArchive archive = ZipFile.OpenRead(e.FullPath))
{
foreach (ZipArchiveEntry entry in archive.Entries)
{
// Outputs relevant file information to the console
Console.WriteLine("File Name: {0}", entry.Name);
Console.WriteLine("File Size: {0} bytes", entry.Length);
Console.WriteLine("Compression Ratio: {0}", ((double)entry.CompressedLength / entry.Length).ToString("0.0%"));
//Identifies the destination file name and path
string ordnername = Path.GetFileNameWithoutExtension(e.FullPath);
//extract the files to the output folder in a safer manner
string ordnerPfad;
if (!File.Exists(ordnername))
{
//Calculates what the new full path for the unzipped file should be
ordnerPfad = Path.Combine(ConfigurationManager.AppSettings["ExtraktionPath"], ordnername);
//Creates the directory (if it doesn't exist) for the new path
Directory.CreateDirectory(ordnerPfad);
if (entry.FullName.EndsWith(".pdf", StringComparison.OrdinalIgnoreCase) |
entry.FullName.EndsWith(".txt", StringComparison.OrdinalIgnoreCase) |
entry.FullName.EndsWith(".xml", StringComparison.OrdinalIgnoreCase))
//Extracts the file to (potentially new) path
entry.ExtractToFile(Path.Combine(ordnerPfad, entry.FullName));
}
} |
Partager