[英]How do you detect the main hard drive letter such as C: drive?
如何檢測C等主硬盤盤符:驅動器?
嘗試
Path.GetPathRoot(Environment.GetFolderPath(Environment.SpecialFolder.System));
這將返回(通常) C:\
但這取決於您如何定義“主”硬盤。 這將為您提供安裝了 Windows 的驅動器。
這應該可以工作(假設您想要 windows 所在的驅動器):
string rootDrive = Path.GetPathRoot(Environment.SystemDirectory);
Environment.GetFolderPath(Environment.SpecialFolder.System).Substring(0,1)
從這里參考。
var d = Directory.GetDirectoryRoot(Environment.GetEnvironmentVariable("windir"));
“SystemDrive”是您想要的 XP 環境變量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.