C#编程-31:获取驱动器信息

1、新建驱动器信息对象:

DriveInfo di = new DriveInfo(@"c:\");

string[] drives = System.Environment.GetLogicalDrives();

2、获取根目录信息:

DirectoryInfo dirInfo = di.RootDirectory;


3、获取所有文件:

FileInfo[] fileNames = dirInfo.GetFiles("*.*");

string[] files = Directory.GetFiles(currentDirName,"*.*");


4、获取所有文件夹:

DirectoryInfo[] dirInfos = dirInfo.GetDirectories("*.*");


5、获取应用程序当前路径:

string currentDirName = Directory.GetCurrentDirectory();


6、设置当前路径:

Directory.SetCurrentDirectory(path);


参考链接:

https://docs.microsoft.com/zh-cn/dotnet/csharp/programming-guide/file-system/how-to-get-information-about-files-folders-and-drives

上一篇:老罗又双叒叕打脸:锤子科技要换名字了?


下一篇:不破不立:求“变”中的魅族这次都变了些什么?