About/Contact

Steve Trefethen

Steve Trefethen is a Director of Engineering at Reply. Contact me

View my LinkedIn profile


Powered by discountASP.NET
referal ID: sdtref
Why recommend discountASP.NET?
$720 in referrals so far!


Calendar

<<  February 2012  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011

View posts in large calendar

Disclaimer

The posts on this weblog are provided AS IS with no warranties, and confer no rights. The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.



FileSystemInfo.LastWriteTime and 12/31/1600

July 08 2010 12:23AM

I’ve been working on an application tracking the age of files and if they reaches a certain threshold an error gets trigged.

FileInfo f = new FileInfo(new SystemPath(m.FolderName).Combine(m.FileName).ToString());
double totalminutes = DateTime.Now.Subtract(f.LastWriteTime).TotalMinutes;
if (totalminutes >= ErrorIntervalInMinutes)

I setup an error message to display information about the files when the error occurs and got something like this:

Error: File (d:\outbound\997_42772_06182010_1504_91.txt) File Time: 12/31/1600 4:00:00 PM Current Time: 6/18/2010 3:06:10 PM has failed to upload via FTP for 215356266.168919 minutes.

Whoa, over 400 years! That’s a lot of minutes not to mention 12/31/1600 looks a bit suspicious. A peek at the documentation for FileInfo.LastWriteTime reveals:

If the file described in the FileSystemInfo object does not exist, this property will return 12:00 midnight, January 1, 1601 A.D. (C.E.) Coordinated Universal Time (UTC), adjusted to local time. 

Ah ha! The list of files being processed in this case is static and files are getting uploaded to an FTP server so clearly the file causing the error is no longer on disk thus the error. Adding an if(!f.Exists) continue; should do the trick.

Now, I didn’t investigate UTC once converted to local time resulting in 12/31/1600 vs. 1/1/1601 but I found my answer and after adding a simple check I was on my way.

FacebookDel.icio.usDigg It!

Tags: .NET | Programming

Comments (2) -

7/8/2010 7:14:57 AM #

Of course, this introduces a race - a file may exist for File.Exists, but be deleted when you get its modification time. How likely that is to be a concern depends on your situation.

Barry Kelly United Kingdom

7/8/2010 1:16:37 PM #

Hey Bary,
  You're right though in this case if File.Exists() it isn't going anywhere though I have another case where that could occur.

Steve Trefethen United States

Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading