using System;
using System.Collection.Generic;
using System.IO;
public class FileSeeker
{
public static string[] RetrieveFilesFrom(string directory, string searchPattern,int level)
{
Listfilenames = new List ();
Stackdirectories = new Stack ()
directories.Push(directory);
while(directories.count!=0)
{
string currentDirectory = directoriesStack.Pop();
foreach(string file in Directory.GetFiles(currentDirectory,searchPattern))
filenames.Add(file);
if((level==-1) || (directories.count != level))
{
foreach(string subDirectory in Directory.GetDirectories(currentDirectory))
directories.Push(subDirectory);
}
}
return filenames.ToArray();
}
}
public class Program
{
public static void Main(string[] args)
{
foreach(string path in FileSeeker.RetrieveFilensFrom(@"C:\Program Files\", "*.exe",-1)
Console.WriteLine(path);
Console.Read();
}
}
Estoy encapsulando todo en un componente con muchas mas funcionalidades, como buscar mediante expresiones regulares, tamaño, fecha de creación, etc. En cuanto lo termine hago un articulo para el sitio de elguille
No comments:
Post a Comment