gpt4 book ai didi

c# - 获取两个日期之间的文件

转载 作者:行者123 更新时间:2023-12-02 20:47:24 25 4
gpt4 key购买 nike

如何列出两个日期之间的文件。现在它会遍历文件夹中的每个文件并返回所有文件。

  protected void btnListItems_Click(object sender, EventArgs e)
{
lblMessage.Visible = false;
//lblEnddatse.Visible = true;
Boolean status = true;
Util objUtil = new Util();
String Message = "";
DateTime SDate = new DateTime();
DateTime EDate = new DateTime();
string str = "";
DataTable tbl = new DataTable();
DataTable dt = new DataTable();
DataRow dr;
String[] s1;


//DirectoryInfo d = new DirectoryInfo();
s1 = Directory.GetFiles(@"C:/PCRequestFiles");
for (int i = 0; i <= s1.Length - 1; i++)
{
if (i == 0)
{
//Add Data Grid Columns with name
dt.Columns.Add("FileName");
dt.Columns.Add("GeneratedTime");
}
//Get each file information
FileInfo f = new FileInfo(s1[i]);
FileSystemInfo f1 = new FileInfo(s1[i]);
dr = dt.NewRow();
//Get File name of each file name
dr["FileName"] = f1.Name;
dr["GeneratedTime"] = f1.CreationTime.Date.ToString("dd/MM/yyyy");
string a = f1.CreationTime.Date.ToString("dd/MM/yyyy");
//Insert collected file details in Datatable
string fromdate = txtFromDate.Text.ToString();
string todate = txtToDate.Text.ToString();

dt.Rows.Add(dr);



if ((f.Length / 1024) > 5000)
{
lblMessage .Text = "" + f1.Name + " had reach its size limit.";
}
else
{ }

}
if (dt.Rows.Count > 0)
{
gvFileGenStatus.DataSource = dt;
gvFileGenStatus.DataBind();
}





}

我试图给出条件,但它不起作用。有没有办法使用日期过滤器来列出目录中的文件名。 感谢您提前提供的所有帮助)。

最佳答案

我确信这会有所帮助:

DirectoryInfo DirInfo = new DirectoryInfo(@"C:/PCRequestFiles");

var files = from f in DirInfo.EnumerateFiles()
where f.CreationTimeUtc < EndDate && f.CreationTimeUtc > StartDate
select f;

关于c# - 获取两个日期之间的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34390903/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com