This post originated from an RSS feed registered with .NET Buzz
by Tim Sneath.
Original Post: Framework BCL Richness
Feed Title: Tim Sneath's Blog
Feed URL: /msdnerror.htm?aspxerrorpath=/tims/Rss.aspx
Feed Description: Random mumblings on Microsoft, .NET, and other topics.
There are times when I take the .NET Framework base class libraries for granted. But
it saves so much time on a daily basis. Today I needed to update a file timestamp
and realised that I didn't have a touch utility on my machine. the FileInfo class
made it quicker to write one from scratch than find and download one!
Here's what I wrote, pared down to the bared bones:
class Touch {
static void Main(string[] args) {
System.IO.FileInfo f = new System.IO.FileInfo(args[0]);
if (f.Exists)
f.LastWriteTime = System.DateTime.Now;
}
}
This version is of course missing support for wildcards and error handling - I leave
that as an exercise for the reader! Incidentally, the FileInfo class also includes
properties for CreationTime and LastAccessTime.