C# Directory SetLastAccessTime

Description

Directory SetLastAccessTime Sets the date and time the specified file or directory was last accessed.

Syntax

Directory.SetLastAccessTime has the following syntax.


public static void SetLastAccessTime(
  string path,
  DateTime lastAccessTime
)

Parameters

Directory.SetLastAccessTime has the following parameters.

  • path - The file or directory for which to set the access date and time information.
  • lastAccessTime - An object that contains the value to set for the access date and time of path. This value is expressed in local time.

Returns

Directory.SetLastAccessTime method returns

Example

The following example demonstrates how to use SetLastAccessTime.


/*from  w w w  .jav a  2s.c o  m*/
using System;
using System.IO;

class Test 
{
    public static void Main() 
    {
        string path = @"c:\MyDir";
        Directory.SetLastAccessTime(path, new DateTime(1985,5,4));

        DateTime dt = Directory.GetLastAccessTime(path);
        Console.WriteLine("The last access time for this directory was {0}", dt);

    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.IO »




BinaryReader
BinaryWriter
Directory
DirectoryInfo
DriveInfo
File
FileInfo
FileStream
MemoryStream
Path
StreamReader
StreamWriter
StringReader
StringWriter