C#使用Directoryinfo类获得目录信息和属性的方法
本文实例讲述了C#使用Directoryinfo类获得目录信息和属性的方法。分享给大家供大家参考。具体如下:
usingSystem;
usingSystem.IO;
classMainClass{
staticvoidMain(string[]args){
FileInfofile=newFileInfo("c:\\a.txt");
//Displaydirectoryinformation.
DirectoryInfodir=file.Directory;
Console.WriteLine("Checkingdirectory:"+dir.Name);
Console.WriteLine("Indirectory:"+dir.Name);
Console.Write("Directoryexists:");
Console.WriteLine(dir.Exists.ToString());
if(dir.Exists){
Console.Write("Directorycreated:");
Console.WriteLine(dir.CreationTime.ToString());
Console.Write("Directorylastupdated:");
Console.WriteLine(dir.LastWriteTime.ToString());
Console.Write("Directorylastaccessed:");
Console.WriteLine(dir.LastAccessTime.ToString());
Console.Write("Directoryattributelist:");
Console.WriteLine(dir.Attributes.ToString());
Console.WriteLine("Directorycontains:"+
dir.GetFiles().Length.ToString()+"files");
}
Console.WriteLine();
}
}
希望本文所述对大家的C#程序设计有所帮助。