def match_dir_or_file_pattern(path, ignore_patterns=None): """ Tries to match the given path with the directory (substring match) or file (enforced full match) patterns. :param path: Valid file path :param ignore_patterns: List of regex patterns that match a file or a directory :return: True if any of the given pattern match """ def escape(pattern): return pattern.replace('\\', '\\\\') expanded_ignores = list_glob_results(ignore_patterns) file_patterns, dir_patterns = partition(expanded_ignores, os.path.isfile) return (any((re.match(escape(pattern), path) for pattern in dir_patterns)) or any((re.fullmatch(escape(pattern), path) for pattern in file_patterns)))
def match_dir_or_file_pattern(path, ignore_patterns=None): """ Tries to match the given path with the directory (substring match) or file (enforced full match) patterns. :param path: Valid file path :param ignore_patterns: List of regex patterns that match a file or a directory :return: True if any of the given pattern match """ def escape(pattern): return pattern.replace('\\', '\\\\') expanded_ignores = list_glob_results(ignore_patterns) file_patterns, dir_patterns = partition( expanded_ignores, os.path.isfile) return ( any((re.match(escape(pattern), path) for pattern in dir_patterns)) or any((re.fullmatch(escape(pattern), path) for pattern in file_patterns)))