正如标题所暗示的,如何获取当前的操作系统驱动器,因此可以将其添加到字符串中,例如:
MessageBox.Show(C:\ + "My Documents");
谢谢
发布于 2011-08-31 04:58:51
添加对System.IO的引用:
using System.IO;
然后在你的代码中,写下:
string path = Path.GetPathRoot(Environment.SystemDirectory);
让我们通过显示一个消息框来尝试一下。
MessageBox.Show($"Windows is installed to Drive {path}");
发布于 2011-08-31 05:00:25
您可以使用Environment.CurrentDirectory获取当前目录。Environment.SystemDirectory将为您提供系统文件夹(即C:\Windows\System32)。Path.GetPathRoot将为您提供路径的根目录:
var rootOfCurrentPath = Path.GetPathRoot(Environment.CurrentDirectory);
var driveWhereWindowsIsInstalled = Path.GetPathRoot(Environment.SystemDirectory);
发布于 2011-08-31 04:59:53
如果您不介意稍微解析一下:Environment.SystemDirectory将返回当前目录。
https://stackoverflow.com/questions/7249715
复制相似问题