作者:手机用户2502915601 | 来源:互联网 | 2023-10-13 18:43
privatestaticvoidgetdir(stringpath,stringextName){try{string[]dirDirectory.GetDirectories(
private static void getdir(string path, string extName)
{
try
{
string[] dir = Directory.GetDirectories(path); //文件夹列表
DirectoryInfo fdir = new DirectoryInfo(path);
FileInfo[] file = fdir.GetFiles();
//FileInfo[] file = Directory.GetFiles(path); //文件列表
if (file.Length != 0 || dir.Length != 0) //当前目录文件或文件夹不为空
{
foreach (FileInfo f in file) //显示当前目录所有文件
{
if (extName.ToLower().IndexOf(f.Extension.ToLower()) >= 0)
{
lst.Add(f);
}
}
foreach (string d in dir)
{
getdir(d, extName);//递归
}
}
}
catch (Exception ex)
{
throw ex;
}
}