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);
    }
}




















Home »
  C# Tutorial »
    IO »




File Attribute
File Security
Directory Attribute
Directory Recursive
Binary File
Text Field
Buffered IO
Create Copy Delete Move
CSV
Drive
File System Watcher
Isolated Storage
MemoryStream
Serialize
Zip