寻找带日期的文件 [英] look for file with date

查看:57
本文介绍了寻找带日期的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


使用下面的代码,可以在下面看到今天的日期文件.

问题:
但是如果今天是星期一,我只想查看具有星期五日期的文件.
请问这怎么可能?
谢谢

Hi,
Using the following code, I can pick up files with dates for today as you see below.

Question:
But if today is monday, I only want to see the files which have friday''s date.
How is this possible please?
Thanks

string[] fileNames = {"abcdef20120216.csv","ijklmn20120215.csv","pqrst20120216.csv"};
DateTime today = DateTime.Now;
string searchDate = 
	string.Format("{0:0000}{1:00}{2:00}.csv",today.Year,today.Month,today.Day);
ArrayList fileNamesArray = new ArrayList();
foreach(string fileName in fileNames){
	if (fileName.EndsWith(searchDate))
		fileNamesArray.Add(fileName);

推荐答案

DateTime matchDate = new DateTime(2012, 2, 20);
var query = from file in files
            where (new FileInfo(file)).LastWriteTime.Date == matchDate
            select file;
matchFiles = query.ToArray<string>();




or

DateTime matchDate = new DateTime(2012, 2, 20);
foreach (string file in files)
    {
    if ((new FileInfo(file)).LastWriteTime.Date == matchDate)
        {
        matchFiles.Add(file);
        }
    }


这篇关于寻找带日期的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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