From 7987e64d3875ac0e175224d81d6815596b9dfba9 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 30 Mar 2017 13:56:32 -0400 Subject: add new file method overloads --- .../IO/ManagedFileSystem.cs | 32 ++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'Emby.Common.Implementations/IO/ManagedFileSystem.cs') 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 GetFiles(string path, bool recursive = false) { - return GetFiles(path, null, true, recursive); + return GetFiles(path, null, false, recursive); } public IEnumerable GetFiles(string path, string[] extensions, bool enableCaseSensitiveExtensions, bool recursive = false) @@ -790,9 +790,37 @@ namespace Emby.Common.Implementations.IO } public IEnumerable GetFilePaths(string path, bool recursive = false) + { + return GetFilePaths(path, null, false, recursive); + } + + public IEnumerable 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 GetFileSystemEntryPaths(string path, bool recursive = false) -- cgit v1.2.3