Set the date and time the specified file or directory was last accessed in CSharp
Description
The following code shows how to set the date and time the specified file or directory was last accessed.
Example
using System;// w w w . j ava2 s. c o m
using System.IO;
class Test
{
public static void Main()
{
string path = @"c:\MyDir";
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
Directory.SetLastAccessTime(path, new DateTime(1985,5,4));
// Get the last access time of a well-known directory.
DateTime dt = Directory.GetLastAccessTime(path);
Console.WriteLine("The last access time for this directory was {0}", dt);
// Update the last access time.
Directory.SetLastAccessTime(path, DateTime.Now);
dt = Directory.GetLastAccessTime(path);
Console.WriteLine("The last access time for this directory was {0}", dt);
}
}