C# Directory SetLastWriteTime

Description

Directory SetLastWriteTime Sets the date and time a directory was last written to.

Syntax

Directory.SetLastWriteTime has the following syntax.


public static void SetLastWriteTime(
  string path,
  DateTime lastWriteTime
)

Parameters

Directory.SetLastWriteTime has the following parameters.

  • path - The path of the directory.
  • lastWriteTime - The date and time the directory was last written to. This value is expressed in local time.

Returns

Directory.SetLastWriteTime method returns

Example

The following example demonstrates how to use SetLastWriteTime.


using System;//  www  .j a  v  a 2s  .c om
using System.IO;

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

       DateTime dt = Directory.GetLastWriteTime(path);
       Console.WriteLine("The last write 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