How to recursively list all the files in a directory in C#?

前端 未结 22 2495
长发绾君心
长发绾君心 2020-11-22 00:07

How to recursively list all the files in a directory and child directories in C#?

22条回答
  •  北海茫月
    2020-11-22 00:39

    Short and simple solution

    string dir = @"D:\PATH";
    
    DateTime from_date = DateTime.Now.Date;
    DateTime to_date = DateTime.Now.Date.AddHours(23);
    var files = Directory.EnumerateFiles(dir, "*.*",SearchOption.AllDirectories).Select(i=>new FileInfo(i))
    .Where(file=>file.LastWriteTime >= from_date && file.LastWriteTime <= to_date);
    foreach(var fl in files)
        Console.WriteLine(fl.FullName);
    

提交回复
热议问题