[C#] How to Copy a directory in C#

There is no method to copy a directory. The copying a directory is a process of creating a new directory that you to want a directory to move to and then copying subdirectory and files.

Get and Set Directory Creation Time

The SetCreationTime and GetCreationTime methods are used to set and get the creation date and time of the specified file. The following code snippet sets and gets the creation time of a file.

// Get and set file creation time
string fileName = @"c:\temp\filetodelete.txt";
File.SetCreationTime(fileName, DateTime.Now);
DateTime dt = File.GetCreationTime(fileName);
Console.WriteLine("File created time: {0}", dt.ToString());

Get and Set File Last Access Time

The SetLastAccessTime and GetLastAccessTime methods are used to set and get the last access date and time of the specified file. The following code snippet sets and gets the last access date and time of a file.

// Get and set file last access time
string fileName = @"c:\temp\filetodelete.txt";
File.SetLastAccessTime(fileName, DateTime.Now);
DateTime dt = File.GetLastAccessTime(fileName);
Console.WriteLine("File last access time: {0}", dt.ToString());

Get and Set File Last Write Time

The SetLastWriteTime and GetLastWriteTime methods are used to set and get the last write date and time of the specified file. The following code snippet sets and gets the last write date and time of a file.

// Get and set file last write timestring 
fileName = @"c:\temp\filetodelete.txt";
File.SetLastWriteTime(fileName, DateTime.Now);
DateTime dt = File.GetLastWriteTime(fileName);
Console.WriteLine("File last write time: {0}", dt.ToString());

 

RSS Thủ thuật & Mẹo vặt

Xem thêm  [C#] How to Decrypt a File in C#

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *