DirectoryInfo类是System.IO命名空间中的一个类,用于操作文件夹和目录。以下是使用DirectoryInfo类的一些常见操作:
string directoryPath = @"C:\MyFolder";
DirectoryInfo directoryInfo = new DirectoryInfo(directoryPath);
string directoryName = directoryInfo.Name;
string directoryFullName = directoryInfo.FullName;
DateTime creationTime = directoryInfo.CreationTime;
directoryInfo.Create();
directoryInfo.Delete();
FileInfo[] files = directoryInfo.GetFiles();
DirectoryInfo[] subDirectories = directoryInfo.GetDirectories();
string newDirectoryPath = @"C:\NewFolder";
directoryInfo.MoveTo(newDirectoryPath);
这些是DirectoryInfo类的一些常见用法。通过使用这些方法,可以方便地操作文件夹和目录。