import os import config def scan(path: str, ignore_excluded: bool = False): path = os.path.expanduser(path) if config.verbosity > 0: print("Scanning: " + path) for root, subdirs, files in os.walk(path): if (not ignore_excluded) and isexcluded(root): if config.verbosity > 1: print("Ignoring: " + root) continue if len(files) > config.maxmimum_file_number: if config.verbosity > 0: print("Too many " + "(" + str(len(files)) + ")" + " files in: " + root) return True def isexcluded(path: str): dirname = os.path.basename(path) in config.excluded_dir_names dirnameinside = any(map(lambda x: "/" + x + "/" in path, config.excluded_dir_names)) fullname = any(map(lambda l: path.startswith(l), excluded)) return dirname or fullname or dirnameinside excluded = list(map(os.path.expanduser, config.excluded_dirs)) list(map(scan, config.watched_dirs))