Glob.cs 902 B

123456789101112131415161718192021222324252627
  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. public static IEnumerable<FileSystemInfoBase> EnumerateFiles(IEnumerable<string> patterns)
  11. {
  12. foreach (var pattern in patterns)
  13. if (IsGlob(pattern))
  14. foreach (var file in GlobExpressions.Glob.Files(Environment.CurrentDirectory, pattern))
  15. yield return new FileInfoWrapper(new FileSystem(), new FileInfo(file));
  16. else
  17. yield return new FileInfoWrapper(new FileSystem(), new FileInfo(pattern));
  18. }
  19. public static bool IsGlob(string path)
  20. {
  21. return path.IndexOfAny(GlobCharacters) >= 0;
  22. }
  23. }
  24. }