コード例 #1
0
        public IEnumerable <string> GetFilePaths(string path, string[] extensions, bool enableCaseSensitiveExtensions, bool recursive = false)
        {
            if (_sharpCifsFileSystem.IsEnabledForPath(path))
            {
                return(_sharpCifsFileSystem.GetFilePaths(path, extensions, enableCaseSensitiveExtensions, recursive));
            }

            var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;

            // On linux and osx the search pattern is case sensitive
            // If we're OK with case-sensitivity, and we're only filtering for one extension, then use the native method
            if (enableCaseSensitiveExtensions && extensions != null && extensions.Length == 1)
            {
                return(Directory.EnumerateFiles(path, "*" + extensions[0], searchOption));
            }

            var files = Directory.EnumerateFiles(path, "*", searchOption);

            if (extensions != null && extensions.Length > 0)
            {
                files = files.Where(i =>
                {
                    var ext = Path.GetExtension(i);
                    if (ext == null)
                    {
                        return(false);
                    }
                    return(extensions.Contains(ext, StringComparer.OrdinalIgnoreCase));
                });
            }

            return(files);
        }