Click here to Skip to main content
14,836,169 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,
I want get count of my files in a directory as like gmail can u guide or send any snippets
Posted
Updated 10-Nov-20 0:35am

1 solution

C#
int fileCount = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories).Length; // Will Retrieve count of all files in directry and sub directries

int fileCount = Directory.GetFiles(path, "*.*", SearchOption.TopDirectory).Length; // Will Retrieve count of all files in directry but not sub directries

int fileCount = Directory.GetFiles(path, "*.xml", SearchOption.AllDirectories).Length; // Will Retrieve count of files XML extension in directry and sub directries

or see here:
http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvcs/thread/3ea19b83-b831-4f30-9377-bc1588b94d23[^]
http://pcheruku.wordpress.com/2008/09/03/c-code-to-get-the-file-count-in-a-directory-recursively/[^]
   
Comments
Mohammad A Rahman 14-May-12 2:57am
   
5
[no name] 29-Aug-12 1:28am
   
this code to count no files in folder ...

but..
i want to delete all files in folder but not recently created 5 files
wcdNail 16-Jul-13 7:09am
   
int fileCount = Directory.GetFiles(path, "\\Windows\\WinSxS\\*.*", SearchOption.TopDirectory).Length;
- What can I do with that situation ?
(on i7 with 6G ram it works about 5-14 seconds)

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




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