C#获取当前系统磁盘符、系统目录、桌面等

1.获取方式如下

Environment.SpecialFolder中定义了许多常用的目录
//获取当前系统磁盘符方法1,返回:C:
string path = Environment.GetEnvironmentVariable("systemdrive");
//获取当前系统磁盘符方法2,返回:C:
string path = Environment.ExpandEnvironmentVariables("%systemdrive%");
Console.WriteLine(path);
//获取当前系统目录
Console.WriteLine("GetFolderPath: {0}",Environment.GetFolderPath(Environment.SpecialFolder.System));
//获取当前系统桌面
Console.WriteLine("GetFolderPath: {0}", Environment.GetFolderPath(Environment.SpecialFolder.System));

 

posted @ 2016-05-17 09:22  天马3798  阅读(4516)  评论(3编辑  收藏  举报