In this method if i'm not mistaken it's searching for inside the files. So when I typed in searchTerm for example "Form1" it found 46 files.
But now I want to change the method without the searchTerm so it will loop over all the files but in the end I want to get List of all the files types. If there are the same dupilcate dont add them to the List so in the end I will get a List with files types items like: cs,txt,xml so I will know what files types there are.
IEnumerable<string> SearchAccessibleFiles(string root, string searchTerm)
{
var files = new List<string>();
foreach (var file in Directory.EnumerateFiles(root).Where(m => m.Contains(searchTerm)))
{
files.Add(file);
}
foreach (var subDir in Directory.EnumerateDirectories(root))
{
try
{
files.AddRange(SearchAccessibleFiles(subDir, searchTerm));
}
catch (UnauthorizedAccessException ex)
{
// ...
}
}
return files;
}
The problem is that if I'm just making GetFiles and the root directory is c:\ then it will stop and will not get any files when it's getting to the directory in windows 10: Documents and Settings
Directory.GetFiles(textBox3.Text, "*.*", SearchOption.AllDirectories).ToList();
Since I didn't find a way to work around with Directory.GetFiles on pass over this directory I'm trying to use the recursive method.