C# 删除文件夹下的文件

/// <summary>
    /// 删除某个时间之前的所有文件
    /// </summary>
    /// <param name="aUrl"></param>
    /// <param name="aTime"></param>
    public static void RemoveFile(string aUrl,DateTime aTime) { 
      var bFiles = Directory.GetFiles(aUrl).Select(r => new {  LastWriteTime = Directory.GetLastWriteTime(r),Path = r }).ToList() ;
      var bDelFiles = bFiles.Where(r => r.LastWriteTime <= aTime).ToList();
      foreach (var item in bDelFiles) { 
        File.Delete(item.Path);
      }
    }
    原文作者:mingjing941018
    原文地址: https://blog.csdn.net/mingjing941018/article/details/124970665
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞