Using the filename without extension you could combine the path and filename without extension using Path.GetFileNameWithoutExtension
and Path.Combine
to create a new path.
Finally just create that directory with Directory.CreateDirectory
so the directory exists when you try to extract the zip-file to your ExtractPath
.
This will unpack all zip-files to the directory where the zip-file being unpacked is, usually all files are in same directory when using OpenFileDialog.
foreach (string file in openFileDialog1.FileNames)
{
String ExtractPath = Path.GetDirectoryName(file);
string directory = "Unzipped " + Path.GetFileNameWithoutExtension(file);
ExtractPath = Path.Combine(ExtractPath, directory);
Directory.CreateDirectory(ExtractPath);
try
{string ExtractPath = Path.GetDirectoryName(file);
If you want all files to be extracted to a specific directory then set the directory outside of the for loop and just combine that path with "Unzipped " + filename.
String unpackPath = @"C:\UnpackPath";
foreach (string file in openFileDialog1.FileNames)
{
string directory = "Unzipped " + Path.GetFileNameWithoutExtension(file);
string ExtractPath = Path.Combine(unpackPath, directory);
Directory.CreateDirectory(ExtractPath);
This will create unpack the files in folders like: "C:\UnpackPath\Unzipped A", "C:\UnpackPath\Unzipped B" (using your example file names).