DirectoryInfo类是System.IO命名空间中的一个类,用于操作目录的相关信息和方法。下面是一些DirectoryInfo类的常用方法和属性的示例用法:
string path = @"C:\MyDirectory";
DirectoryInfo directory = new DirectoryInfo(path);
string fullPath = directory.FullName;
string directoryName = directory.Name;
DirectoryInfo parentDirectory = directory.Parent;
DateTime creationTime = directory.CreationTime;
DateTime lastWriteTime = directory.LastWriteTime;
bool exists = directory.Exists;
directory.Create();
directory.Delete();
FileInfo[] files = directory.GetFiles();
foreach (FileInfo file in files)
{
Console.WriteLine(file.Name);
}
DirectoryInfo[] subDirectories = directory.GetDirectories();
foreach (DirectoryInfo subDirectory in subDirectories)
{
Console.WriteLine(subDirectory.Name);
}
这些只是DirectoryInfo类的一些常用方法和属性的示例用法,你可以根据自己的需求进一步了解和使用DirectoryInfo类的其他方法和属性。