Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List Files in a directory by creation date

Status
Not open for further replies.

EzehM

Programmer
Feb 27, 2003
86
GB
I have a directory with files created over a period of time. How can I list files created over a period of the last 7 days (i.e. Files created today, yesterday, the day before yesterday and so on).

I have looked at the DateTime Object, but haven’t had so much luck.

Thanks in advance.
 
Code:
DirectoryInfo dir = new DirectoryInfo("directory path");
foreach(FileInfo file in dir.GetFiles())
{
   if (file.CreationDate.Date >= DateTime.Today.AddDays(-7))
   {
       //file created in the last 7 days
   }
}

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top