我亲自在本机测试过了,代码如下:
string[] list = this.recursed(@"D:\Downloads\", new string[] { "*.jpg", "*.png", "*.gif" });
foreach (string str in list) {
this.txtProcessInfo.Text += str + Environment.NewLine;
}
public string[] recursed(string path, string[] patterns) {
string[] arrList = new string[0];
foreach (string str in patterns) {
string[] list = Directory.GetFiles(path, str, SearchOption.AllDirectories);
if (list != null) {
string[] temp = arrList;
arrList = new string[arrList.Length + list.Length];
Array.Copy(temp, 0, arrList, 0, temp.Length);
Array.Copy(list, 0, arrList, temp.Length, list.Length);
}
}
return arrList;
}
简单!
学学习!