If you are looking for multiple files in the same directory structure, you should find all the files in this directory structure once, and then search them in memory. There is no need to access the file system again and again.
EDIT: There's an elegant way to do this, with LINQ - and a less elegant way, without. Here is the LINQ path:
using System;
using System.IO;
using System.Linq;
class Test
{
static void Main()
{
var textFiles =
Directory.GetFiles("I:\\pax", "*.txt", SearchOption.AllDirectories)
.ToLookup(file => Path.GetFileName(file),
file => Path.GetDirectoryName(file));
string[] fileNames = File.ReadAllLines(@"c:\file.txt");
string targetDirectory = "C:\\" + "textBox1.Text" + @"\\N\\O\\";
foreach (string fileName in fileNames)
{
string tmp = fileName + ".txt";
foreach (string directory in textFiles[tmp])
{
string source = Path.Combine(directory, tmp);
string target = Path.Combine(targetDirectory, tmp);
File.Copy(source, target);
}
}
}
}
, , LINQ. , , , - . , ? (, a.txt , "a" .)