I am writing the C# function which retrieves some files matched pattern.
Input : C:\abc*\abc?\testfile.*
Output : All files matched.
I thought I could make it by recursion. But it was not easy :(
Do you have a nice algorithm?
Update:
I made it. Thanks Kieren :)
void PrintAllFiles(DirectoryInfo currentDir,
string currentPattern, string nextPatten)
{
DirectoryInfo[] dis = currentDir.GetDirectories(currentPattern);
if (dis.Length > 0)
{
string[] remainPattern = nextPatten.Split("\\".ToCharArray());
if (remainPattern.Length > 0)
{
foreach (DirectoryInfo di in dis)
{
PrintAllFiles(di, remainPattern.First(),
string.Join("\\", remainPattern.Skip(1).ToArray()));
}
}
}
FileInfo[] fis = currentDir.GetFiles(currentPattern);
foreach (FileInfo fi in fis)
{
Console.WriteLine(fi.DirectoryName + "\\" + fi.Name);
}
}