获取某个日期范围内修改的所有文件

发布于 2024-12-02 13:09:04 字数 104 浏览 4 评论 0原文

我们有一个 asp.net、C# 应用程序,其中需要获取所有修改日期为黑白 startdate 和 enddate 的文件。我们怎样才能做到这一点? 还想获取最近 3 个月内未修改的所有文件吗?

We have a asp.net,C# application in which there is a requirement to get all the files whose date modified will be b/w startdate and enddate . How can we achieve this ?
Also want to get all the files not modified for last 3 months ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

荒岛晴空 2024-12-09 13:09:04

根据这篇文章,你可以这样做:

var directory = new DirectoryInfo(your_dir);
DateTime from_date = DateTime.Now.AddMonths(-3);
DateTime to_date = DateTime.Now;
var files = directory.GetFiles()
  .Where(file=>file.LastWriteTime >= from_date && file.LastWriteTime <= to_date);

According to this post, you could do this:

var directory = new DirectoryInfo(your_dir);
DateTime from_date = DateTime.Now.AddMonths(-3);
DateTime to_date = DateTime.Now;
var files = directory.GetFiles()
  .Where(file=>file.LastWriteTime >= from_date && file.LastWriteTime <= to_date);
终陌 2024-12-09 13:09:04

看看这个问题和答案:

如何使用以下命令查找目录中的最新文件.NET,并且没有循环?

您可以从那里开始并将 where 子句添加到答案中提供的 LINQ 查询中:)

look at this question and answer:

How to find the most recent file in a directory using .NET, and without looping?

you can start from there and add your where clause to the provided LINQ query in the answer :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文