简单C# 遍历文件和文件夹
class FileTester
{
static void Main(string[] args)
{
DirectoryInfo dir = new DirectoryInfo(@"C:\Users\User\Desktop\a");
ListFile(dir);
Console.ReadKey();
}
public static void ListFile(DirectoryInfo dir)
{
DirectoryInfo[] infos = dir.GetDirectories();
foreach (DirectoryInfo info in infos)
{
Console.WriteLine(info.FullName);
ListFile(info);
}
FileInfo[] files = dir.GetFiles();
foreach(FileInfo file in files)
{
Console.WriteLine(file.FullName);
}
}
}