c# - how to read all files in particular folder and filter more than one type? -
this question has answer here:
to loop through files of 1 type, :
foreach (string file in directory.enumeratefiles(folderpath, "*.txt")) { (code here) }
taken how read files inside particular folder
is there way have 2 tags other making 2 loops? having *.bmp, *.png...
note : answer accepted down here way more simple 1 in proposed answer, both works.
you can concatenate 2 results this
foreach (string file in directory.enumeratefiles(folderpath, "*.txt").concat(directory.enumeratefiles(folderpath, "*.bmp"))) { // (code here) }
or make function so
ienumerable<string> enumeratefiles(string folderpath, params string[] patterns) { return patterns.selectmany(pattern => directory.enumeratefiles(folderpath, pattern)); } void later() { foreach (var file in enumeratefiles(".", "*.config", "*.exe")) { // (code here) } }
Comments
Post a Comment