fork download
  1. using static System.Console;
  2. using System.IO;
  3. using System.Collections.Generic;
  4.  
  5. public class Program {
  6. public static void Main() {
  7. foreach (var file in FileUtil.GetFiles("c:\\", "aria2c.exe")) WriteLine(file);
  8. }
  9. }
  10.  
  11. public static class FileUtil {
  12. public static IEnumerable<string> GetFiles(string root, string searchPattern) {
  13. var pending = new Stack<string>();
  14. pending.Push(root);
  15. while (pending.Count != 0) {
  16. var path = pending.Pop();
  17. string[] next = null;
  18. try {
  19. next = Directory.GetFiles(path, searchPattern);
  20. }
  21. catch { } //aqui você pode colocar log, aviso ou fazer algo útil se tiver problemas
  22. if (next != null && next.Length != 0) foreach (var file in next) yield return file;
  23. try {
  24. next = Directory.GetDirectories(path);
  25. foreach (var subdir in next) pending.Push(subdir);
  26. }
  27. catch { } //aqui você pode colocar log, aviso ou fazer algo útil se tiver problemas
  28. }
  29. }
  30. }
  31.  
  32. //https://pt.stackoverflow.com/q/75167/101
Success #stdin #stdout 0.02s 16740KB
stdin
Standard input is empty
stdout
Standard output is empty