FileSystemInfo.LastAccessTime Property gets or sets the time the current file or directory was last accessed. : File System « File Stream « C# / C Sharp






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

1.File System Watcher DemoFile System Watcher Demo
2.FileSystem Watcher
3.FileSystemInfo Class provides the base class for both FileInfo and DirectoryInfo objects.
4.FileSystemEventArgs: Changed, Created, Deleted.