第一种(用通配符)
string[] fileNameX = Directory.GetFiles(@"D:\Sjdc", "*.xls?");
Array array = Array.CreateInstance(typeof(string),fileNameX.Length);
fileNameX.CopyTo(array, );
第二种
string[] fileNameX = Directory.GetFiles(@"D:\Sjdc", "*.*");
List<string> lists = new List<string>();
for (int i = ; i < fileNameX.Length; i++)
{
string fileNamei = fileNameX[i].ToLower();
if (fileNamei.EndsWith(".xls") || fileNamei.EndsWith(".xlsx"))
{
lists.Add(fileNamei);
}
}
Array array = Array.CreateInstance(typeof(string), lists.Count);
lists.CopyTo((string[])array, );
第三种
var files = Directory.GetFiles(@"D:\Sjdc", "*.*", SearchOption.AllDirectories).Where(s => s.EndsWith(".XLSX") || s.EndsWith(".XLS"));
List<string> listFile = new List<string>();
foreach (string s in files)
{
listFile.Add(s);
}