This is the code in my method :
t = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
string[] textfiles = ApplyAllFiles(t, "*.txt", ProcessFile).ToArray();
Then i did also:
s = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
string[] textfiles = ApplyAllFiles(s, "*.jpg", ProcessFile).ToArray();
And the ApplyAllFiles method:
static void ProcessFile(string path) {/* ... */}
static IEnumerable<string> ApplyAllFiles(string folder, string searchPattern, Action<string> fileAction)
{
IEnumerable<string> files = Directory.GetFiles(folder, searchPattern);
foreach (string file in files)
{
fileAction(file);
}
foreach (string subDir in Directory.GetDirectories(folder))
{
try
{
files = files.Concat(ApplyAllFiles(subDir, searchPattern, fileAction));
}
catch
{
// swallow, log, whatever
}
}
return files;
}
Its not getting files from the main directory for example the first main directory is: C:\Users\bout0_000\Documents And i have in this directory some text files. It will get all the text files from sub
directories in Documents but it will never get the text file that are in C:\Users\bout0_000\DocumentsHow can i get more then one extention for example i did "*.jpg" but i want also to get bmp files png files and gif files.