原文作者不讓轉載,就發個鏈子這里吧,大家自己過去看。
https://codedefault.com/s/how-do-i-call-directory-getfiles-with-multiple-filters-in-csharp-application/
用作備份。這里簡單說一下思路,就是 Directory.GetFiles.Where 中使用 Lambda 表達式來過濾。
再細節一點,一種在 Where 中 用到 .EndWith,另一種是在 Where 中用到 Regex.IsMatch 的正則表達式。
比如,要過濾出.jpg/.png/.tiff/.bmp/.gif 這些文件,那么這條正則表達式就是:
"^.+\.(jpg|png|bmp|gif|tiff)$"