Finding if a file is less than 24 hours old

  • Thread starter Thread starter timnels
  • Start date Start date
T

timnels

Is there a simple way using the File class to see is a file is older
than 24 hours?
 
Is there a simple way using the File class to see is a file is older
than 24 hours?

You can use the FileInfo class, something like this:

FileInfo fi = new FileInfo(@"C:\foo.txt");
DateTime dt = fi.CreationTime;
 
Well, you can use the static GetLastAccessTime, GetLastWriteTime and
GetCreationTime methods to determine what the last time the file was
accessed, written to, or when it was created. You can then compare those
times to the time in question and see if it is past 24 hours (by subtracting
one of the times returned from those methods from the time in question, and
then seeing if the resulting TimeSpan is greater than 24 hours.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top