예제 #1
0
        private static string[] GetFiles(CommandOption includeOption, CommandOption excludeOption, string defaultInclude)
        {
            var matcher = new Microsoft.Extensions.FileSystemGlobbing.Matcher();

            if (includeOption.HasValue())
            {
                foreach (var include in includeOption.Values)
                {
                    matcher.AddInclude(include);
                }
            }
            else if (!string.IsNullOrEmpty(defaultInclude))
            {
                matcher.AddInclude(defaultInclude);
            }

            foreach (var exclude in excludeOption.Values)
            {
                matcher.AddExclude(exclude);
            }

            var currentDirectoryInfo = new DirectoryInfo(Directory.GetCurrentDirectory());
            var directoryInfoWrapper = new DirectoryInfoWrapper(currentDirectoryInfo);

            var fileMatchResult = matcher.Execute(directoryInfoWrapper);

            return(fileMatchResult.Files.Select(f => Path.GetFullPath(f.Path)).ToArray());
        }
예제 #2
0
        private static IFileInfo[] GetFiles(
            IEnumerable <string> includes,
            IEnumerable <string> excludes,
            IDirectoryInfo parentDir)
        {
            var matcher = new Microsoft.Extensions.FileSystemGlobbing.Matcher();

            foreach (var include in includes)
            {
                matcher.AddInclude(include);
            }

            foreach (var exclude in excludes)
            {
                matcher.AddExclude(exclude);
            }

            var fileMatchResult =
                matcher.Execute(
                    new Microsoft.Extensions.FileSystemGlobbing.Abstractions.DirectoryInfoWrapper(
                        new DirectoryInfo(parentDir.FullName)));

            return(fileMatchResult.Files
                   .Select(f =>
                           parentDir.FileSystem.FileInfo.FromFileName(
                               Path.GetFullPath(Path.Combine(
                                                    parentDir?.ToString() ?? throw new InvalidOperationException("Could not find path."),
                                                    f.Path))))
                   .ToArray());
        }
예제 #3
0
        public static ICollection <string> Execute(string dir, string[] includes, string[] excludes)
        {
            var dirInfo        = new DirectoryInfo(dir);
            var dirInfoWrapper = new DirectoryInfoWrapper(dirInfo);

            var matcher = new Microsoft.Extensions.FileSystemGlobbing.Matcher();

            foreach (var incl in includes ?? new string[0])
            {
                matcher.AddInclude(incl);
            }
            foreach (var excl in excludes ?? new string[0])
            {
                matcher.AddExclude(excl);
            }

            var result = matcher.Execute(dirInfoWrapper);

            return(result.Files
                   .Select(f => Path.Combine(dir, f.Path))
                   .ToList()
                   );
        }
예제 #4
0
        private static FileInfo[] GetFiles(
            IEnumerable <string> includes,
            IEnumerable <string> excludes,
            DirectoryInfo parentDir)
        {
            var matcher = new Microsoft.Extensions.FileSystemGlobbing.Matcher();

            foreach (var include in includes)
            {
                matcher.AddInclude(include);
            }

            foreach (var exclude in excludes)
            {
                matcher.AddExclude(exclude);
            }

            var fileMatchResult = matcher.Execute(new DirectoryInfoWrapper(parentDir));

            return(fileMatchResult.Files
                   .Select(f => new FileInfo(Path.GetFullPath(Path.Combine(parentDir.ToString(), f.Path))))
                   .ToArray());
        }