Extract files without the directories

Sep 14, 2009 at 4:51 AM

hi all,

though you could help. i've been trying to extract files from a zip file. the structure of the zip file is

sample.zip

    |--- directory1

               |--- file1.txt

               |--- file2.txt

 

when extracted

    |--- directory1

               |--- file1.txt

               |--- file2.txt

 

what i want to do is that when the zip file is extracted, the directory will not be among the extracted files. i've tried the code below

 

foreach (ZipEntry z in zip1)
     {
          if (!z.IsDirectory)
          {
               z.Extract(targetDirectory, false);
          }
     }
but this do not work. it automatically writes the directory1 among the extracted files. would be great if you guys could help me. thanks

Coordinator
Sep 14, 2009 at 6:11 AM
Edited Sep 14, 2009 at 7:18 AM

Set the property ZipFile.FlattenFoldersOnExtract  , before calling ZipEntry.Extract();

This property is available in v1.8.4.19 and later.