Glob.cs 827 B

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