• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 255
  • Last Modified:

displaying older files in a directory

The below displays all files in the MyPath directory, but how would I modify it to only display files whose datetime stamp is older than 24 hours?

static void Main(string[] args)
{
  string[] files = System.IO.Directory.GetFiles(MyPath);

  foreach(string file in files)
  {
    string FileName = Path.GetFileName(file);
    Console.WriteLine(FileName)
  }
}
0
arichexe
Asked:
arichexe
1 Solution
 
dfu23Commented:
Add an IF statement inside of your FOR loop that is something along these lines:

if (File.GetCreationTime(file) < DateTime.Now.AddHours(-24))
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now