检查是否存在Windows驱动器

R.S*_*R.S 3 c# windows

我要编写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
      }
   }
}
Run Code Online (Sandbox Code Playgroud)

KF2*_*KF2 6

试试这个:

   //Get Drive names with DriveInfo.GetDrives()
 var drives= DriveInfo.GetDrives();

       foreach (var item in drives)
       {
           //Do Something
       }
Run Code Online (Sandbox Code Playgroud)

编辑(检查存在)

   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)
       {

       }
Run Code Online (Sandbox Code Playgroud)