This project is read-only.

How do you count only certain files types

Sep 29, 2011 at 9:24 AM

Hi guys I'm using dotnetzip to gain how many files are within a zip the only problem is it also count the folders. How can I change it so it only counts .txt and .ini files or does'nt count folders.

Thanks Tom

The code so far is down below


  int count;
            using (ZipFile zip = ZipFile.Read(knowledgeplanning))
                count = zip.Count;


Oct 3, 2011 at 12:16 AM

You'd have to iterate through the entries and examine each one. The way to determine if an entry is a folder or a file., is to check the IsDirectory property on the ZipEntry.

The code might look like this:

int count = 0;
using (ZipFile zip = ZipFile.Read(archiveName)) 
    int C = zip.Count; 
    for(int i=0, C = zip.Count; i < C; i++) 
       ZipEntry e = zip[i];
       if (!e.IsDirectory) count++;
Console.WriteLine("There are {0} file entries in the zip archive.", count);