Glob.cs 964 B

1234567891011121314151617181920212223242526272829303132
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.IO.Abstractions;
  5. namespace ArcToolkitCLI.Util
  6. {
  7. internal class Glob
  8. {
  9. public static readonly char[] GlobCharacters =
  10. {
  11. '*',
  12. '{',
  13. '}',
  14. '[',
  15. ']',
  16. '?'
  17. };
  18. public static IEnumerable<FileSystemInfoBase> EnumerateFiles(IEnumerable<string> patterns)
  19. {
  20. foreach (var pattern in patterns)
  21. if (IsGlob(pattern))
  22. foreach (var file in GlobExpressions.Glob.Files(Environment.CurrentDirectory, pattern))
  23. yield return new FileInfoWrapper(new FileSystem(), new FileInfo(file));
  24. else
  25. yield return new FileInfoWrapper(new FileSystem(), new FileInfo(pattern));
  26. }
  27. public static bool IsGlob(string path) { return path.IndexOfAny(GlobCharacters) >= 0; }
  28. }
  29. }