2
Answers

How to unzip and open a folder using c#

Sujeet Raman

Sujeet Raman

2y
753
1

Hi,

I have a c# program which will unzip all the zipped file.But I need to open the unzipped folder and visible only .txt files.How can I do that?

below code will unzip all files but i want to open that folder and get only selected files(.txt or .xlsx)

in my destination path(here extractPathForCurrentZip) i shoud only see .txt files from diffrent unzipped folder

my code to unzip:

 string startPath = @"C:\zipdirectory\";
        string extractPath = @"C:\unzipdirectory\";
        Directory.GetFiles(startPath, "*.zip", SearchOptions.AllDirectories).ToList()
            .ForEach(zipFilePath => {
                var extractPathForCurrentZip = Path.Combine(extractPath, Path.GetFileNameWithoutExtension(zipFilePath));
                if(!Directory.Exists(extractPathForCurrentZip))
                {
                    Directory.CreateDirectory(extractPathForCurrentZip);
                }
                ZipFile.ExtractToDirectory(zipFilePath, extractPathForCurrentZip);
        });

 

Answers (2)