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);
参考链接: