mirror of
				https://github.com/jellyfin/jellyfin.git
				synced 2025-11-04 03:27:21 -05:00 
			
		
		
		
	Merge pull request #13691 from NooNameR/noonamer/add_pattern_search
Add ability to provide search pattern to GetFiles
This commit is contained in:
		
						commit
						480244e111
					
				@ -560,11 +560,23 @@ namespace Emby.Server.Implementations.IO
 | 
				
			|||||||
        /// <inheritdoc />
 | 
					        /// <inheritdoc />
 | 
				
			||||||
        public virtual IEnumerable<FileSystemMetadata> GetFiles(string path, bool recursive = false)
 | 
					        public virtual IEnumerable<FileSystemMetadata> GetFiles(string path, bool recursive = false)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            return GetFiles(path, null, false, recursive);
 | 
					            return GetFiles(path, "*", recursive);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <inheritdoc />
 | 
					        /// <inheritdoc />
 | 
				
			||||||
        public virtual IEnumerable<FileSystemMetadata> GetFiles(string path, IReadOnlyList<string>? extensions, bool enableCaseSensitiveExtensions, bool recursive = false)
 | 
					        public virtual IEnumerable<FileSystemMetadata> GetFiles(string path, string searchPattern, bool recursive = false)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return GetFiles(path, searchPattern, null, false, recursive);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <inheritdoc />
 | 
				
			||||||
 | 
					        public virtual IEnumerable<FileSystemMetadata> GetFiles(string path, IReadOnlyList<string>? extensions, bool enableCaseSensitiveExtensions, bool recursive)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            return GetFiles(path, "*", extensions, enableCaseSensitiveExtensions, recursive);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <inheritdoc />
 | 
				
			||||||
 | 
					        public virtual IEnumerable<FileSystemMetadata> GetFiles(string path, string searchPattern, IReadOnlyList<string>? extensions, bool enableCaseSensitiveExtensions, bool recursive = false)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var enumerationOptions = GetEnumerationOptions(recursive);
 | 
					            var enumerationOptions = GetEnumerationOptions(recursive);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -572,10 +584,12 @@ namespace Emby.Server.Implementations.IO
 | 
				
			|||||||
            // If we're OK with case-sensitivity, and we're only filtering for one extension, then use the native method
 | 
					            // If we're OK with case-sensitivity, and we're only filtering for one extension, then use the native method
 | 
				
			||||||
            if ((enableCaseSensitiveExtensions || _isEnvironmentCaseInsensitive) && extensions is not null && extensions.Count == 1)
 | 
					            if ((enableCaseSensitiveExtensions || _isEnvironmentCaseInsensitive) && extensions is not null && extensions.Count == 1)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                return ToMetadata(new DirectoryInfo(path).EnumerateFiles("*" + extensions[0], enumerationOptions));
 | 
					                searchPattern = searchPattern.EndsWith(extensions[0], StringComparison.Ordinal) ? searchPattern : searchPattern + extensions[0];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                return ToMetadata(new DirectoryInfo(path).EnumerateFiles(searchPattern, enumerationOptions));
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            var files = new DirectoryInfo(path).EnumerateFiles("*", enumerationOptions);
 | 
					            var files = new DirectoryInfo(path).EnumerateFiles(searchPattern, enumerationOptions);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (extensions is not null && extensions.Count > 0)
 | 
					            if (extensions is not null && extensions.Count > 0)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
 | 
				
			|||||||
@ -157,8 +157,36 @@ namespace MediaBrowser.Model.IO
 | 
				
			|||||||
        /// <returns>All found files.</returns>
 | 
					        /// <returns>All found files.</returns>
 | 
				
			||||||
        IEnumerable<FileSystemMetadata> GetFiles(string path, bool recursive = false);
 | 
					        IEnumerable<FileSystemMetadata> GetFiles(string path, bool recursive = false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// Gets the files.
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <param name="path">The path in which to search.</param>
 | 
				
			||||||
 | 
					        /// <param name="searchPattern">The search string to match against the names of files. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but it doesn't support regular expressions.</param>
 | 
				
			||||||
 | 
					        /// <param name="recursive">If set to <c>true</c> also searches in subdirectories.</param>
 | 
				
			||||||
 | 
					        /// <returns>All found files.</returns>
 | 
				
			||||||
 | 
					        IEnumerable<FileSystemMetadata> GetFiles(string path, string searchPattern, bool recursive = false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// Gets the files.
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <param name="path">The path in which to search.</param>
 | 
				
			||||||
 | 
					        /// <param name="extensions">The file extensions to search for.</param>
 | 
				
			||||||
 | 
					        /// <param name="enableCaseSensitiveExtensions">Enable case-sensitive check for extensions.</param>
 | 
				
			||||||
 | 
					        /// <param name="recursive">If set to <c>true</c> also searches in subdirectories.</param>
 | 
				
			||||||
 | 
					        /// <returns>All found files.</returns>
 | 
				
			||||||
        IEnumerable<FileSystemMetadata> GetFiles(string path, IReadOnlyList<string>? extensions, bool enableCaseSensitiveExtensions, bool recursive);
 | 
					        IEnumerable<FileSystemMetadata> GetFiles(string path, IReadOnlyList<string>? extensions, bool enableCaseSensitiveExtensions, bool recursive);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// Gets the files.
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <param name="path">The path in which to search.</param>
 | 
				
			||||||
 | 
					        /// <param name="searchPattern">The search string to match against the names of files. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but it doesn't support regular expressions.</param>
 | 
				
			||||||
 | 
					        /// <param name="extensions">The file extensions to search for.</param>
 | 
				
			||||||
 | 
					        /// <param name="enableCaseSensitiveExtensions">Enable case-sensitive check for extensions.</param>
 | 
				
			||||||
 | 
					        /// <param name="recursive">If set to <c>true</c> also searches in subdirectories.</param>
 | 
				
			||||||
 | 
					        /// <returns>All found files.</returns>
 | 
				
			||||||
 | 
					        IEnumerable<FileSystemMetadata> GetFiles(string path, string searchPattern, IReadOnlyList<string>? extensions, bool enableCaseSensitiveExtensions, bool recursive);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /// <summary>
 | 
					        /// <summary>
 | 
				
			||||||
        /// Gets the file system entries.
 | 
					        /// Gets the file system entries.
 | 
				
			||||||
        /// </summary>
 | 
					        /// </summary>
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user