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類的一些常見用法。通過使用這些方法,可以方便地操作文件夾和目錄。