C#最简单的递归出所有的文件和文件

public List<FileInfo> FileInfoList { get; private set; } = new List<FileInfo>();
public List<DirectoryInfo> DirectoryInfoList { get; private set; } = new List<DirectoryInfo>();


public void FindFoldersAndFiles(string path)
{
foreach (string fileName in Directory.GetFiles(path))
{
FileInfoList.Add(new FileInfo(fileName));
}
foreach (string directory in Directory.GetDirectories(path))
{
DirectoryInfoList.Add(new DirectoryInfo(directory));
FindFoldersAndFiles(directory);
}
}

posted @ 2021-09-12 21:25  晨晞gg  阅读(172)  评论(0编辑  收藏  举报