Set the date and time a directory was last written to in CSharp

Description

The following code shows how to set the date and time a directory was last written to.

Example


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

class Test 
{
    public static void Main() 
    {
            string path = @"c:\MyDir";
            if (!Directory.Exists(path)) 
            {
                Directory.CreateDirectory(path);
            } 
            else 
            {
                // Take an action that will affect the write time.
                Directory.SetLastWriteTime(path, new DateTime(2010,4,3));
            }

            // Get the last write time of a well-known directory.
            DateTime dt = Directory.GetLastWriteTime(path);
            Console.WriteLine("The last write time for this directory was {0}", dt);
      
            //Update the last write time.
            Directory.SetLastWriteTime(path, DateTime.Now);
            dt = Directory.GetLastWriteTime(path);
            Console.WriteLine("The last write 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