352
Chương 9: File, thư mục, và I/O
Console.WriteLine("Checking directory: " + dir.Name);
Console.WriteLine("In directory: " + dir.Parent.Name);
Console.Write("Directory exists: ");
Console.WriteLine(dir.Exists.ToString());
if (dir.Exists) {
Console.Write("Directory created: ");
Console.WriteLine(dir.CreationTime.ToString());
Console.Write("Directory last updated: ");
Console.WriteLine(dir.LastWriteTime.ToString());
Console.Write("Directory last accessed: ");
Console.WriteLine(dir.LastAccessTime.ToString());
Console.Write("Directory attribute list: ");
Console.WriteLine(dir.Attributes.ToString());
Console.WriteLine("Directory contains: " +
dir.GetFiles().Length.ToString() + " files");
}
Console.ReadLine();
}
}
Nếu bạn thực thi lệnh
FileInformation c:\windows\win.ini
, kết xuất có thể như sau:
Checking file: win.ini
File exists: True
File created: 2001-08-23 8:00:00 AM
File last updated: 2003-03-22 9:55:16 AM
File last accessed: 2003-05-26 2:21:53 PM
File size (bytes): 2128
File attribute list: Archive
Checking directory: windows
In directory: c:\
Directory exists: True
Directory created: 2000-01-01 8:03:33 AM