Reputation: 11310
I have a csv file with file names and I need to search for those filenames in a particular directory. I can read thru a csv file and get all the filenames but would like to know how can I search for those files.
Any pointers would be would of great help
Upvotes: 2
Views: 133
Reputation: 880
It's pretty easy, there are many different ways you can do this. I prefer the "exists" method if I am just trying to find out if the files are there.
string SearchDirectory = "C:\\SomeDirectory\\";
List<String> FilesToSearch = new List<string>();
//Populate FilesToSearch from your csv...
foreach (String CurrentFileToSearch in FilesToSearch)
{
if (System.IO.File.Exists(SearchDirectory + TargetFileName))
{
//Do Something!
}
}
Upvotes: 2
Reputation: 25505
System.IO.Directory.Getfiles will give you a list of files in a particular directory. If you need to so more intensive searching. You may want to use the windows indexing.
Upvotes: 3
Reputation: 10306
What about trying following code snippet.
Directory.EnumerateFiles(directory, fileName, SearchOption.AllDirectories);
Upvotes: 3