351
Chương 9: File, thư mục, và I/O
using System;
using System.IO;
public class FileInformation {
private static void Main(string[] args) {
if (args.Length == 0) {
Console.WriteLine("Please supply a file name:”);
return;
}
FileInfo file = new FileInfo(args[0]);
// Hiển thị thông tin file.
Console.WriteLine("Checking file: " + file.Name);
Console.WriteLine("File exists: " + file.Exists.ToString());
if (file.Exists) {
Console.Write("File created: ");
Console.WriteLine(file.CreationTime.ToString());
Console.Write("File last updated: ");
Console.WriteLine(file.LastWriteTime.ToString());
Console.Write("File last accessed: ");
Console.WriteLine(file.LastAccessTime.ToString());
Console.Write("File size (bytes): ");
Console.WriteLine(file.Length.ToString());
Console.Write("File attribute list: ");
Console.WriteLine(file.Attributes.ToString());
}
Console.WriteLine();
// Hiển thị thông tin thư mục.
DirectoryInfo dir = file.Directory;