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

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -