C# Directory GetLastAccessTime

Description

Directory GetLastAccessTime Returns the date and time the specified file or directory was last accessed.

Syntax

Directory.GetLastAccessTime has the following syntax.


public static DateTime GetLastAccessTime(
  string path
)

Parameters

Directory.GetLastAccessTime has the following parameters.

  • path - The file or directory for which to obtain access date and time information.

Returns

Directory.GetLastAccessTime method returns A structure that is set to the date and time the specified file or directory was last accessed. This value is expressed in local time.

Example

The following example demonstrates how to use GetLastAccessTime.


//w  w  w. ja v a 2s  .c o m
using System;
using System.IO;

public class DirectoryUTCTime
{
  public static void Main()
  {
     string n = @"C:\test\newdir";
     DateTime dtime1 = new DateTime(2014, 1, 3);
     DateTime dtime2 = new DateTime(1999, 1, 1);
    
     Directory.SetCreationTime(n, dtime1);
     Directory.SetLastAccessTimeUtc(n, dtime1);
    
     Console.WriteLine("Creation Date: {0}", Directory.GetCreationTime(n));
     Console.WriteLine("UTC creation Date: {0}", Directory.GetCreationTimeUtc(n));
     Console.WriteLine("Last write time: {0}", Directory.GetLastWriteTime(n));
     Console.WriteLine("UTC last write time: {0}", Directory.GetLastWriteTimeUtc(n));
     Console.WriteLine("Last access time: {0}", Directory.GetLastAccessTime(n));
     Console.WriteLine("UTC last access time: {0}", Directory.GetLastAccessTimeUtc(n));
    
     Directory.SetLastWriteTimeUtc(n, dtime2);
     Console.WriteLine("Changed last write time: {0}", Directory.GetLastWriteTimeUtc(n));
  }
}




















Home »
  C# Tutorial »
    System.IO »




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