diff options
| author | Luke <luke.pulverenti@gmail.com> | 2017-03-30 14:03:40 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-03-30 14:03:40 -0400 |
| commit | bfb177f8b64f611b8fb2376d86799085f3ef9204 (patch) | |
| tree | 7bf0cc412a66acbe5e8fa94f8f4487b6d00d43a2 /Emby.Common.Implementations/IO/ManagedFileSystem.cs | |
| parent | 4165bcb1940e843a0a7b0dfe708b27f182e58bf3 (diff) | |
| parent | 46646b95fde4701e9a879f11e66ad461f805a6a4 (diff) | |
Merge pull request #2558 from MediaBrowser/dev
Dev
Diffstat (limited to 'Emby.Common.Implementations/IO/ManagedFileSystem.cs')
| -rw-r--r-- | Emby.Common.Implementations/IO/ManagedFileSystem.cs | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/Emby.Common.Implementations/IO/ManagedFileSystem.cs b/Emby.Common.Implementations/IO/ManagedFileSystem.cs index ed940eca5..4d7a86821 100644 --- a/Emby.Common.Implementations/IO/ManagedFileSystem.cs +++ b/Emby.Common.Implementations/IO/ManagedFileSystem.cs @@ -662,7 +662,7 @@ namespace Emby.Common.Implementations.IO public IEnumerable<FileSystemMetadata> GetFiles(string path, bool recursive = false) { - return GetFiles(path, null, true, recursive); + return GetFiles(path, null, false, recursive); } public IEnumerable<FileSystemMetadata> GetFiles(string path, string[] extensions, bool enableCaseSensitiveExtensions, bool recursive = false) @@ -791,8 +791,36 @@ namespace Emby.Common.Implementations.IO public IEnumerable<string> GetFilePaths(string path, bool recursive = false) { + return GetFilePaths(path, null, false, recursive); + } + + public IEnumerable<string> GetFilePaths(string path, string[] extensions, bool enableCaseSensitiveExtensions, bool recursive = false) + { var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; - return Directory.EnumerateFiles(path, "*", searchOption); + + // 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; } public IEnumerable<string> GetFileSystemEntryPaths(string path, bool recursive = false) |
