Env : C #, VStudio 2013, 4.5 Framework, Winforms
Purpose : getting the number of files (number) in the folder and subfolder that correspond to the extensions stored in the string array. An extension array may be with a "." no. {".dat", "TXT", "tzd"}
What I have done so far : when I have a "." everything works in the array of extensions: {".dat", ". txt", ". msg"}
I tried Replace but always returned 0.
Working code (only if always with the character "." In the string array):
string[] ext= new string[] { ".txt", ".msg", ".dat" }; totalFilesInTN = Directory.EnumerateFiles(dlg1.SelectedPath, "*.*", SearchOption.AllDirectories) .Count(s => ext.Any(s1 => s1 == Path.GetExtension(s)));
The code does not work (always return 0):
string[] ext= new string[] { "txt", ".msg", "dat" }; totalFilesInTN = Directory.EnumerateFiles(dlg1.SelectedPath, "*.*", SearchOption.AllDirectories) .Count(s => ext.Any(s1 => s1 == Path.GetExtension(s).Replace(".", "")));
source share