Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi i used SharpCopress, i want get count of files (this code return count of files+directory)

C#
private int GetCountFiles(FileInfo rarFileInfo)
        {
            return ArchiveFactory.Open(rarFileInfo.FullName).Entries.Count();
        }

I do not know how to change for filter up code...

What I have tried:

no tried,
no tried
,
no tried
,
Posted
Updated 12-Jul-19 20:38pm
Comments
BillWoodruff 13-Jul-19 2:03am    
Come back when you've tried something.
ahmadamiri 13-Jul-19 3:50am    
i tired, but don't like LINQ
BillWoodruff 13-Jul-19 9:27am    
pathetic excuse for being lazy !

1 solution

From what I get from API Examples · adamhathcock/sharpcompress Wiki · GitHub[^]
you can do it like this:
int fileCount = 0;
var archive = ArchiveFactory.Open(@"C:\Code\sharpcompress\TestArchives\sharpcompress.zip");

foreach (var entry in archive.Entries)
{
	if (!entry.IsDirectory)
	{
		Console.WriteLine(entry.Key);
        fileCount++;
	}
}

Console.WriteLine("File count = " + fileCount);
 
Share this answer
 
Comments
BillWoodruff 13-Jul-19 9:29am    
are we here to write code for people who have not even tried ... anything ? fyi: I am not voting on your solution.
RickZeeland 13-Jul-19 14:21pm    
Maybe you are right and I should be more strict about this, have a nice weekend :)
BillWoodruff 14-Jul-19 0:47am    
Hi Rick, I apologize if my words were, in any way, disrespectful of you. Your fine technical mind, and generous contributions to CP and QA, are very appreciated ! sincerely, Bill

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900