File times with C#

I have been working on a little web widget that I don’t have done yet, but in the course of writing it I wanted to do some file time checking so as to create a sort of pseudo cache, to stop the need to bombard a webservice. Note, these are notes to myself for the future.


using System;
using System.IO;

public class fileTime {

public static void Main( string[] args ) {
string fileName = "/home/username/test.txt";
string time;
string now;

if ( File.Exists( fileName )) {
Console.WriteLine( "Yes, file exists." );
time = File.GetLastWriteTime( fileName ).ToString();
Console.WriteLine( "Last write time was: " + time );
now = DateTime.Now.ToString();
Console.WriteLine( "Time is now: " + now );
} else {
Console.WriteLine( "No such file" );
}
} // end Main
} // end class

I wanted to throw this together so I could just test it out.

About Nathan Powell

I am a middle aged technologist freak-ball.
This entry was posted in programming. Bookmark the permalink.

Comments are closed.