Learn how to a build a cloud-first strategyRegister Now


displaying older files in a directory

Posted on 2006-03-23
Medium Priority
Last Modified: 2010-04-16
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);
Question by:arichexe
1 Comment
LVL 14

Accepted Solution

dfu23 earned 300 total points
ID: 16277615
Add an IF statement inside of your FOR loop that is something along these lines:

if (File.GetCreationTime(file) < DateTime.Now.AddHours(-24))

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question