如何获取目录最后修改日期= textboxdate并在此目录c#获取文件 [英] how get directory last modify date = textboxdate and get file in this directory c#

查看:450
本文介绍了如何获取目录最后修改日期= textboxdate并在此目录c#获取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这么多的目录和这些目录中的文件太多了,我想获取目录最后修改日期,如果目录中的修改日期和LT =文本日期获取文件,并获得数= txtnumber得到FILEDATA怎么能我这样做...

I have so many directories and these directories has so many files, I want get directory last modify date if directory Modify date <= textbox date get files and get number = txtnumber get filedata how can I do this...

private void button1_Click(object sender, EventArgs e)
{
    string path = @"E:\Voip Caller Record\890001";
    var allfiles = System.IO.Directory.GetFiles(path, "*.*", System.IO.SearchOption.AllDirectories);       
}

在这里输入的形象描述

推荐答案

您可以通过目录路径的的DirectoryInfo 的实例并使用的 DirectoryInfo的 LastWriteTime 属性来找出在目录上次写入(修改):

You can pass the directory path to the instance of the DirectoryInfo and use the DirectoryInfo class, LastWriteTime property to figure out when the directory was last written to (modified):

DirectoryInfo info = new DirectoryInfo("myDirPath");
if (info.LastWriteTime > someDate){
    var allfiles = Directory.GetFiles(path, "*.*", System.IO.SearchOption.AllDirectories);
    //do something on allfiles
}

如果这是最后一次一定时间后写的,那么你所表现出什么让该目录中的所有文件,你可以继续你想要的。

If it was last written after certain time, then get all the files in that directory by what you have shown and you could proceed as you want.

编辑:

如果您需要子目录,而不是文件,你可以使用 Directory.GetDirectories()来代替。并获得该目录上次写入时间,只需做同样的事情如上:

If you need sub-directories instead of files, you could use Directory.GetDirectories() instead. And to get the directory last write time, simply do the same thing as above:

var alldirs = Directory.GetDirectories("myRootPath")
    .Select(x => new DirectoryInfo(x));
foreach (var dir in alldirs) {
    if (dir.LastWriteTime > someDateTime) {
        //do something
    }
}

这篇关于如何获取目录最后修改日期= textboxdate并在此目录c#获取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆