Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C#
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);
Posted

1 solution

C#
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
C#
DateTime matchDate = new DateTime(2012, 2, 20);
foreach (string file in files)
    {
    if ((new FileInfo(file)).LastWriteTime.Date == matchDate)
        {
        matchFiles.Add(file);
        }
    }
 
Share this answer
 
Comments
arkiboys 16-Feb-12 7:13am    
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900