title: C# - Count all Files in directory including Zip in Zip etc
body: <p>I have a directory where all kind of random data is in it including ZIP archives which could also include ZIP archives itself and so on. What I want to count is all data except the ZIP archives.</p>
  <p>My attempt with starting to count the data in the ZIP files:</p>
  <pre><code>static void Main(string[] args)
          {
              DirectoryInfo directoryInfo = new DirectoryInfo(@&quot;C:\Temp&quot;);
              int count = 0;
  
              foreach (FileInfo file in directoryInfo.GetFiles())
              {
                  if (file.Extension.Equals(&quot;.zip&quot;))
                  {
                      count += ZipFileCount(file.FullName);
                  }
  
              }
              Console.WriteLine(count);
          }
  
          public static int ZipFileCount(String zipFileName)
          {
              using (ZipArchive archive = ZipFile.Open(zipFileName, ZipArchiveMode.Read))
              {
                  foreach (var entry in archive.Entries)
                  {
                      if (!String.IsNullOrEmpty(entry.Name))
                      {
                          count += 1;
  
                          if (entry.Name.Substring(entry.Name.Length - 3).Equals(&quot;zip&quot;))
                          {
                              ZipFileCount(entry.Name);
                          }
  
                      }
  
                  }
                  return count;
              }
          }
  </code></pre>
  <p>That didn't work out as <code>ZipFileCount(entry.Name)</code> does not provide the right entries in the ZIP of the ZIP.</p>
  <p>Anybody can help me out to fix this?</p>