C# Directory GetLastWriteTime

Description

Directory GetLastWriteTime Returns the date and time the specified file or directory was last written to.

Syntax

Directory.GetLastWriteTime has the following syntax.


public static DateTime GetLastWriteTime(
  string path
)

Parameters

Directory.GetLastWriteTime has the following parameters.

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

Returns

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

Example

The following example demonstrates how to use GetLastWriteTime.


//from  w w w. j  a  v  a 2  s .c om
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