c# 遍历目录
标签:lis 递归 else director search lin reac write arch
public static List TraverseDirector(string dir, bool isTraveSubDirFlag, bool isFilterSuffix, string suffix)
{
string suffix_ = "*.*";
if (isFilterSuffix)
{
suffix_ = suffix;
}
List list = new List();
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 listSubFolder = TraverseDirector(fsinfo.FullName, isTraveSubDirFlag, isFilterSuffix, suffix);//递归调用
list.AddRange(listSubFolder);
}
}
else
{
//Console.WriteLine(fsinfo.FullName);//输出文件的全部路径
list.Add(fsinfo.FullName);
}
}
return list;
}
c# 遍历目录
标签:lis 递归 else director search lin reac write arch
原文地址:https://www.cnblogs.com/scotth/p/10579880.html
文章来自:
搜素材网的
编程语言模块,转载请注明文章出处。
文章标题:
c# 遍历目录
文章链接:http://soscw.com/essay/93412.html
评论