How to get count of files in a directory in C#?
To get the number of Files in a directory we can use:int fileCount = Directory.GetFiles(path, "*.*", SearchOption.TopDirectory).Length;
If you want to get the number of files including sub-directories you can use:
int fileCount = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories).Length;
If you want to get the number of files in a directory for a specific extension you can use:
int fileCount = Directory.GetFiles(path, "*.xml", SearchOption.AllDirectories).Length;