FileSystemInfo.LastAccessTime Property gets or sets the time the current file or directory was last accessed.
using System;
using System.IO;
class Touch
{
static void Main(string[] args)
{
FileInfo fi = new FileInfo("c:\\a.txt");
touchFile(fi);
}
static void touchFile(FileSystemInfo fsi)
{
Console.WriteLine("Touching: {0}", fsi.FullName);
try
{
fsi.CreationTime = fsi.LastWriteTime = fsi.LastAccessTime = DateTime.Now;
}
catch (Exception e)
{
Console.WriteLine("Error: {0}", e.Message);
}
}
}
Related examples in the same category