├── ListOfFolders.zip (Locked with password)
└── FolderA
└── FolderB
└── FolderC
└── Hack.exe (Allows you to choose where to install certain folders that are inside the zip)
using System;
using System****;
using System****.Compression;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string zipPath = @"c:\example\start.zip";
string extractPath = @"c:\example\extract";
using (ZipArchive archive = ZipFile.OpenRead(zipPath))
{
foreach (ZipArchiveEntry entry in archive.Entries)
{
if (entry.FullName.EndsWith(".txt", StringComparison.OrdinalIgnoreCase))
{
entry.ExtractToFile(Path.Combine(extractPath, entry.FullName));
}
}
}
}
}
}
IO.Compression
public static void extractDir(string directoryName, string zipPath, string extractPath)
{
//Open Zip Archive
using (ZipArchive archive = ZipFile.OpenRead(zipPath))
{
//For each file in archive
foreach (ZipArchiveEntry entry in archive.Entries)
{
//If Directory name equals directoryName Splitting the Directory path, to get the first directory name of the path
//Console.WriteLine(Path.GetDirectoryName(entry.FullName));
if (Path.GetDirectoryName(entry.FullName).Split('/')[0].Equals(directoryName) || Path.GetDirectoryName(entry.FullName).Split('\\')[0].Equals(directoryName))
{
//Combine the destination path
string combinedPath = Path.Combine(extractPath, Path.GetDirectoryName(entry.FullName));
//Create directory(s)
if (!Directory.Exists(combinedPath))
{
Directory.CreateDirectory(combinedPath);
}
//Check if the entry is a directory
if (!Directory.Exists(Path.Combine(combinedPath, entry.Name)))
{
entry.ExtractToFile(Path.Combine(combinedPath, entry.Name));
}
}
}
}
}