i wrote a code to search a file in the external devices like external hard disk

read the code line by line so u can understand properly

private static void SearchForFiles(string path, string pattern, List<string> SearchResults) 
       {    
        foreach (string file in Directory.GetFiles(path, pattern)) 
           {     
           SearchResults.Add(file);    
        }      
      foreach (string dir in Directory.GetDirectories(path)) 
           {   
             try       
         {      
              SearchForFiles(dir, pattern, SearchResults);
                } 
               catch (Exception ex)  
              {     
               
    }        
    }   
     }

private void button1_Click(object sender, EventArgs e)
        {
          
 string myString;
            List<string> SearchResults = new List<string>();
            DriveInfo[] allDrives = DriveInfo.GetDrives();

            foreach (DriveInfo d in allDrives)
            {
if(d.Name.ToString() != "C:\\" && d.Name.ToString() != "D:\\")

                if (d.IsReady == true)
                {
                    myString = String.Format(" {0}", d.Name);
          SearchForFiles(myString, "vlc.exe", SearchResults);
                 
                }
            }
            foreach (string s in SearchResults)
            {

        Process.Start(s); <<<<<<<===== problem is here i'll get error when i compile as "the system cannot find the file specified"
      
            } 
}

so please any body guide me or correct my code please


thank you

Where is 's' defined? Why are you starting it as a process?

i will explain you my question in details

i am searching a file which is in the External harddisk
once the file is searched the path of the file will be in the
variable string s
by using process . start(s);
i wanted to open the serched file

I really don't see how that error could happen (despite the terrible tabs). Your best bet is to figuire out what s is when it throws the exception, and make sure there's an actual file there.

This article has been dead for over six months. Start a new discussion instead.