比如判断 I 盘是否存在,存在运行 A 程序   不存在运行B 程序 代码怎么写?

解决方案 »

  1.   

    string[] drives = Directory.GetLogicalDrives();获得所有的逻辑盘符
      

  2.   

    Environment.GetFolderPath(Environment.SpecialFolder.System)
      

  3.   

     System.IO.Directory.Exists("PATH")
      

  4.   

    System.IO.Directory.GetLogicalDrives();   
      

  5.   

    判断某个盘符是否存在就用directory,要是对某个盘有更多操作就用directoryInfo进行更多的目录操作。
    至于判断某个程序是否在运行,那就要检查A进程是否存在了。
      

  6.   

    If Directory.Exist("I:\") = False ThenEnd If
      

  7.   


    using System.IO;
    using System.Diagnostic;
    void Run(string fileA,string fileB)
    {
    if(Directory.Exists("I:\\")
       Process.Start(fileA);
    else
       Process.Start(fileB);
    }
      

  8.   


    这样的代码让我很不解!
    拿一个bool值跟另一个bool值做比较有意义吗?
      

  9.   


                 DriveInfo[] allDrives = DriveInfo.GetDrives();
                 foreach (DriveInfo d in allDrives)
                 {
                     if (d.Name.StartsWith("D"))
                     {
                         MessageBox.Show("A function");
                         break;
                     }
                     else MessageBox.Show("B Function");
                 }
    这个做参考
      

  10.   

    你的方法 OK  
    只是
    using System.Diagnostic; 少了个字母
    using System.Diagnostics;
      

  11.   

    下面代码是获取所有盘符:namespace WindowsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                string[] dir = new string[10];
                dir = Directory.GetLogicalDrives();
                for (int i = 0; i < dir.Length; i++)
                {
                    textBox1.Text += dir[i] + "\r\n";
                }
            }
        }
    }