The creation time is the time the file is saved to the computer, while the modification time is the last time the content is changed
Read file creation, modification, access time
FileInfo fi = new FileInfo ("C://test.txt");
Console.WriteLine (FI. Creationtime.tostring ());
Console.WriteLine (FI. Lastwritetime.tostring ());
Console.WriteLine (FI. Lastaccesstime.tostring ());
Change (set) file creation, modification, access time
File.setcreationtime ("C://test.txt", DateTime.Now.AddYears (-1));
File.setlastwritetime ("C://test.txt", DateTime.Now.AddYears (-2));
File.setlastaccesstime ("C://test.txt", DateTime.Now.AddYears (-3));
The namespaces for FileInfo and File are:
System.IO
================================================
As an example of file read-only and hidden properties, other properties, such as "Archive", "system", and so on, are similar methods.
Read-only and hide-from-file properties
FileInfo fi = new FileInfo ("C://test.txt");
if (FI. Attributes & fileattributes.readonly) = = fileattributes.readonly)
{
Console.WriteLine ("is read Only");
}
Else
{
Console.WriteLine ("Not read Only");
}
if (FI. Attributes & Fileattributes.hidden) = = Fileattributes.hidden)
{
Console.WriteLine ("is hidden");
}
Else
{
Console.WriteLine ("Not Hidden");
}
Set file read-only and hidden properties
FileInfo fi = new FileInfo ("C://test.txt");
Fi. Attributes = fi. Attributes | fileattributes.readonly | Fileattributes.hidden; Fayi
File.setattributes ("C://test.txt", fi. Attributes | fileattributes.readonly | Fileattributes.hidden); Law II
As you can see, you can either set the Attributes property or use the SetAttributes method of File to come to the end.
Note that, regardless of what to do, first get the original properties of the file, if you do not get the original properties of the file, is directly fileattributes.readonly | Fileattributes.hidden, then, some properties may be lost, such as the file may have an "archive" attribute, if this is set directly, the archive property is lost.
Canceling file read-only and hidden properties
FileInfo fi = new FileInfo ("C://test.txt");
Fi. Attributes = fi. Attributes & ~fileattributes.readonly & ~fileattributes.hidden; Fayi
File.setattributes ("C://test.txt", fi. Attributes & ~fileattributes.readonly & ~fileattributes.hidden); Law II
Similar to Settings, just some of the arithmetic symbols have changed. Note that the online argument is to set the property directly to Fileattributes.normal, which is not correct, which not only cancels the read-only and hidden properties, but may also cancel some other properties, such as "archive".
Description
Improper property settings may prevent files from appearing in Windows Explorer, but they do exist, and you can use Fileattributes.normal to display the files for easy operation.
Easy to read, change file creation, modification, access time in C #