public bool IsMatch(string fileToMatch) { Debug.Assert(!string.IsNullOrEmpty(fileToMatch)); // We do the matching using one of three code paths, depending on the value of _filenamePattern and _regex. if (_regex != null) { string normalizedFileToMatch = FileUtilities.GetFullPathNoThrow(Path.Combine(_currentDirectory, fileToMatch)); return(_regex.IsMatch(normalizedFileToMatch)); } if (_filenamePattern != null) { // Check file name first as it's more likely to not match. string filename = Path.GetFileName(fileToMatch); if (!FileMatcher.IsMatch(filename, _filenamePattern)) { return(false); } var normalizedFileToMatch = FileUtilities.GetFullPathNoThrow(Path.Combine(_currentDirectory, fileToMatch)); return(normalizedFileToMatch.StartsWith(_currentDirectory, StringComparison.OrdinalIgnoreCase)); } return(FileUtilities.ComparePathsNoThrow(_unescapedFileSpec, fileToMatch, _currentDirectory, alwaysIgnoreCase: true)); }
private bool ShouldSkipEntry(ZipArchiveEntry zipArchiveEntry) { bool result = false; if (_includePatterns.Length > 0) { result = _includePatterns.All(pattern => !FileMatcher.IsMatch(FileMatcher.Normalize(zipArchiveEntry.FullName), pattern)); } if (_excludePatterns.Length > 0) { result |= _excludePatterns.Any(pattern => FileMatcher.IsMatch(FileMatcher.Normalize(zipArchiveEntry.FullName), pattern)); } return(result); }
private IEnumerable <string> EnumerateFullFileSystemPaths(string path, string searchPattern, bool includeFiles, bool includeDirectories) { FindPredicate predicate = (ref ReadOnlySpan <char> fileName) => { return(FileMatcher.IsAllFilesWildcard(searchPattern) || FileMatcher.IsMatch(fileName, searchPattern)); }; FindTransform <string> transform = (ref ReadOnlySpan <char> fileName) => Path.Join(path.AsSpan(), fileName); IEnumerable <string> directories = includeDirectories ? _directoryCache.EnumerateDirectories(path, searchPattern, predicate, transform) : Enumerable.Empty <string>(); IEnumerable <string> files = includeFiles ? _directoryCache.EnumerateFiles(path, searchPattern, predicate, transform) : Enumerable.Empty <string>(); return(Enumerable.Concat(directories, files)); }
/// <summary> /// Same as <see cref="IsMatch" /> but the argument is expected to be a normalized path. /// </summary> public bool IsMatchNormalized(string normalizedFileToMatch) { Debug.Assert(!string.IsNullOrEmpty(normalizedFileToMatch)); // We do the matching using one of three code paths, depending on the value of _filenamePattern and _regex. if (_regex != null) { return(_regex.IsMatch(normalizedFileToMatch)); } if (_filenamePattern != null) { // Check file name first as it's more likely to not match. string filename = Path.GetFileName(normalizedFileToMatch); if (!FileMatcher.IsMatch(filename, _filenamePattern)) { return(false); } return(normalizedFileToMatch.StartsWith(_currentDirectory, StringComparison.OrdinalIgnoreCase)); } return(string.Equals(_unescapedFileSpec, normalizedFileToMatch, StringComparison.OrdinalIgnoreCase)); }
public bool MatchesFileName(string fileName) { return(FileMatcher.IsMatch(fileName)); }
/// <returns>The number of times the <param name="itemToMatch"></param> appears in this fragment</returns> public virtual int MatchCount(string itemToMatch) { return(FileMatcher.IsMatch(itemToMatch) ? 1 : 0); }