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

Status
Not open for further replies.

EzehM

Programmer
Feb 27, 2003
86
GB
Please how can I list (Console.WriteLine) files in a directory that were created today.

foreach (FileInfo file in directory.GetFiles())
{
// List files that were created today
Console.WriteLine(?);
}

Thanks in advance

 
Code:
int filesSkipped = 0;
foreach (FileInfo file in directory.GetFiles())
{
  try
  {
    if(file.CreationTime.Date == DateTime.Today)
    {
      Console.WriteLine(file.FullName);
    }
  }
  catch (IOException) 
  {
    filesSkipped++;
  }
}
Console.WriteLine("Skipped {0} files", filesSkipped);

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Thanks...

if(file.CreationTime.Date == DateTime.Today)

I was trying

if(file.CreationTime == DateTime.Today)- Date missing

Thanks a lot

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top