[英]Check is windows drive exists
我要編寫C#代碼來檢查C,D,E ......(Windows磁盤驅動器)是否存在? 最后找到客戶端窗口中存在哪個驅動器,復制我的文件。
我想編寫類似於以下邏輯的代碼:
If ( !Exist(Drive "C:\" ) )
{
If ( !Exist(Drive "D:\" ) )
{
If ( !Exist(Drive "E:\" ) )
{
...
search to fined existence drive
copy file to a path of that existence drive
}
}
}
嘗試這個:
//Get Drive names with DriveInfo.GetDrives()
var drives= DriveInfo.GetDrives();
foreach (var item in drives)
{
//Do Something
}
編輯 (檢查存在)
var drives= DriveInfo.GetDrives();
if (drives.Where(data => data.Name == "C:\\").Count() == 1 &&
drives.Where(data => data.Name == "D:\\").Count() == 1 &&
drives.Where(data => data.Name == "E:\\").Count() == 1)
{
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.