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; }