标签:lis 递归 else director search lin reac write arch
public static List<string> TraverseDirector(string dir, bool isTraveSubDirFlag, bool isFilterSuffix, string suffix)
{
string suffix_ = "*.*";
if (isFilterSuffix)
{
suffix_ = suffix;
}
List<String> list = new List<string>();
DirectoryInfo d = new DirectoryInfo(dir);
FileSystemInfo[] fsinfos = d.GetFileSystemInfos(suffix_, SearchOption.TopDirectoryOnly);//filter file format
//FileSystemInfo[] fsinfos = d.GetFileSystemInfos();//
foreach (FileSystemInfo fsinfo in fsinfos)
{
if (fsinfo is DirectoryInfo) //判断是否为文件夹
{
if (isTraveSubDirFlag)
{
List<String> listSubFolder = TraverseDirector(fsinfo.FullName, isTraveSubDirFlag, isFilterSuffix, suffix);//递归调用
list.AddRange(listSubFolder);
}
}
else
{
//Console.WriteLine(fsinfo.FullName);//输出文件的全部路径
list.Add(fsinfo.FullName);
}
}
return list;
}
标签:lis 递归 else director search lin reac write arch
原文地址:https://www.cnblogs.com/scotth/p/10579880.html