I need to count the number of files in a folder in .NET 4: The count will return number of all files except the .db file in the folder.
Option 1:
IEnumerable<string> enumerables = Directory.EnumerateFiles(strPath, "*.*", SearchOption.TopDirectoryOnly);
int iNumFiles = 0;
foreach (string f in enumerables)
{
if (!f.EndsWith(".db"))
iNumFiles++;
}
//iNumFiles is the count
Option 2:
int iNumFiles = 0;
IEnumerable<string> enumerables1 = Directory.EnumerateFiles(strPath, "*.*", SearchOption.TopDirectoryOnly);
IEnumerable<string> enumerables2 = Directory.EnumerateFiles(strPath, "*.db", SearchOption.TopDirectoryOnly);
iNumFiles = enumerables1.Count() - enumerables2.Count();
//iNumFiles is the count
Is there any other simpler but better methods (using RegEx or something else) that I should use?
EDIT: Should I keep the .db file or how useful it is? All I know it is the database (cache) of folder contents.
This is messing up my file count.
Thanks for reading.