I currently have this code:
foreach (string file in openFileDialog1.FileNames)
{
String ExtractPath = Path.GetDirectoryName(file);
try
{
using (ZipFile zip = ZipFile.Read(file))
{
zip.ExtractProgress += ExtractProgress;
foreach (ZipEntry e in zip)
{
try
{
e.Extract(ExtractPath,ExtractExistingFileAction.OverwriteSilently); // true => overwrite existing files
}
catch
{
}
}
}
}
catch
{
}
}
This works fine and extracts one or more selected zip files at the same time. But I'm confused about how I should go about creating a separate directory for each file and placing each file into the created directory.
Example:
User selects 2 zip files to extract. The 2 zip files are called "A.zip" and "B.zip"
I would like to programatically put the extracted files into their own directory so I can sift through them for further use.
So the zip file "A.zip" would extracted and the files extracted would be put into a folder called "Unzipped A" and the zip file "B.zip" would be extracted and the file extracted would put into a folder called "Unzipped B".
I'm sorry if this is confusing. Help would be greatly appreciated.
Okay so after using and editing MatteKarla's snippets I now have this:
foreach (string file in openFileDialog1.FileNames)
{
string directory = Path.GetDirectoryName(file) + @"\Unzipped " + Path.GetFileNameWithoutExtension(file);
var GetFiles = Directory.GetFiles(directory, "*.txt", SearchOption.AllDirectories).Where(s => s.EndsWith(".txt"));
foreach (string text in GetFiles)
{
MessageBox.Show("Text found", "File");
}
}
This searches the extracted files in my created directory for a .txt file and it works perfectly, I was just wondering if this is the proper way to do it or is there a more efficient way?