You can use the GetFiles
method of class Directory
, which returns an array of strings with the name of each file found.
You just need to tell the folder where the search will be done, in your case, C:\
;
The search filter, in its case the file name;
And the search option, in your case, AllDirectories
to search in all sub-folders.
Follow the code:
string arquivo = "arquivo.txt";
string[] files = Directory.GetFiles("C:\", arquivo, SearchOption.AllDirectories);
foreach (string file in files)
{
Process.Start(file); //abre o arquivo
Process.Start(new FileInfo(file).DirectoryName);//abre a pasta do arquivo
}