예제 #1
0
        private IEnumerable <string> GetPaths(string root, string path)
        {
            if (path.StartsWith(".\\") || path.StartsWith(".//"))
            {
                path = path.Substring(2);
            }
            var prefix  = "";
            var toFind  = new[] { '*', '[', '{' };
            var matches = path.Select((x, i) => (x, i, isMatch: toFind.Contains(x)));

            if (matches.Any())
            {
                var match = path.Select((x, i) => (x, i, isMatch: toFind.Contains(x)))
                            .FirstOrDefault(x => x.isMatch);

                prefix = path.Substring(0, match.i);
                path   = path.Substring(match.i);
                root   = GetPath(root, prefix);
            }

            if (Path.IsPathRooted(path))
            {
                return(new[] { Path.GetFullPath(path) });
            }
            else
            {
                var rootPAth    = Path.GetFullPath(root);
                var glob        = new Glob.Glob(path);
                var files       = Directory.GetFiles(rootPAth, "*.*", SearchOption.AllDirectories);
                var filesMapped = files.Select(x => new
                {
                    p   = x,
                    sub = x.Substring(rootPAth.Length)
                });
                var filter = filesMapped.Where(x => glob.IsMatch(x.sub));
                return(filter.Select(x => x.p).ToList());
            }
        }
예제 #2
0
        public void GlobIncludeOnlySpecificDirectory(string filePath)
        {
            var include = new GLOB("**/Tests/**");

            Assert.True(include.IsMatch(filePath));
        }
예제 #3
0
        public void GlobExcludeSpecificDirectory(string filePath)
        {
            var include = new GLOB("**/Tests/**");

            Assert.False(include.IsMatch(filePath));
        }
예제 #4
0
        public void GlobIncludeAllWithExtensions(string filePath)
        {
            var include = new GLOB("*.{cs,txt,json,xml,md}");

            Assert.True(include.IsMatch(filePath));
        }