如何获得当前的Windows目录例如C:\在C# [英] How to get current windows directory e.g. C:\ in C#

查看:216
本文介绍了如何获得当前的Windows目录例如C:\在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所暗示的,你怎么能得到当前操作系统的驱动,所以你可以在一个字符串,如添加:

As the title suggests, how can you get the current OS drive, so you could add it in a string e.g.:

MessageBox.Show(C:\ + "My Documents");

感谢

推荐答案

添加一个系统的IO参考,

Add a System IO reference,

using System IO;

然后再编写code这样的;

Then Write your code like this;

string path = Path.GetPathRoot(Environment.SystemDirectory);

这code将设置路径到本地驱动器号已安装的Windows。您可以使用上面的变量更多的进一步的修改。

This code will set path to the Local Drive Letter that Windows is been installed. You can use the above variable for more further modifications.

例如:

MessageBox.Show("Windows is installed to Drive " + path);

这篇关于如何获得当前的Windows目录例如C:\在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆