2013-03-21 32 views
1

代码:我怎样才能GetFiles只有2种类型?

string[] arrFileEntries = Directory.GetFiles(MapPath("..\\Pictures\\"), "*.jpg", "*.png"); 

错误:

的最接近匹配的重载方法System.IO.Directory.GetFiles(字符串,字符串,System.IO.SearchOption)具有一些无效参数

回答

2

你试试下面的代码使用临朐: -

var files = Directory.GetFiles(MapPath("..\\Pictures\\"), "*.*", SearchOption.AllDirectories) 
      .Where(s => s.EndsWith(".jpg") || s.EndsWith(".png")); 
1

尝试以下.......两个阵列获取数据,并把它们合并

string[] array1 = Directory.GetFiles(@"C:\", "*.jpg"); 
string[] array2 = Directory.GetFiles(@"C:\", "*.png"); 

string[] newArray = new string[array1.Length + array2.Length]; 
Array.Copy(array1, newArray, array1.Length); 
Array.Copy(array2, 0, newArray, array1.Length, array2.Length);