Framework BCL Richness

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.

Comments (0)

Skip to main content