using System.IO;//先添加命名空间
static void Main(string[] args)
{
string fle = @"D:\123\123.txt";
FileInfo fileInfo = new FileInfo(fle);
Console.WriteLine("取创建日期:\t"+fileInfo.CreationTime);
Console.WriteLine("取父路径:\t" + fileInfo.Directory);
Console.WriteLine("取完整路径:\t" + fileInfo.DirectoryName);
Console.WriteLine("是否存在:\t" + fileInfo.Exists);
Console.WriteLine("取扩展名:\t" + fileInfo.Extension);
Console.WriteLine("取文件路径:\t" + fileInfo.FullName);
Console.WriteLine("取只读属性:\t" + fileInfo.IsReadOnly);
Console.WriteLine("取访问时间:\t" + fileInfo.LastAccessTime);
Console.WriteLine("取修改时间:\t" + fileInfo.LastWriteTime);
Console.WriteLine("取文件大小:\t" + fileInfo.Length+ "(字节)");
Console.WriteLine("取文件名:\t" + fileInfo.Name);
Console.ReadKey();
}
运行结果:
![]()