c#遍历指定目录下的所有图片

2024-12-03 16:48:34
推荐回答(3个)
回答1:

我亲自在本机测试过了,代码如下:
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;
}

回答2:

简单!

回答3:

学学习!