displaying older files in a directory

Posted on 2006-03-23
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

    Add an IF statement inside of your FOR loop that is something along these lines:

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now