def walk_through_folders(parent_folder, configuration_folder_structure, root_folder_name): if type(parent_folder) is not str: raise Exception if type(root_folder_name) is not str: raise Exception if type(configuration_folder_structure) is not ConfigurationFolder: raise Exception current_folder = Folder(root_folder_name) for dir in os.listdir(parent_folder): path = os.path.join(parent_folder, dir) if os.path.isdir(path): folder = Folder(dir) temp_conf_folder = None for conf_folder in configuration_folder_structure.all_folders(): if str(folder) == str(conf_folder): if conf_folder.is_excluded(): break else: current_folder.add_folder(walk_through_folders(os.path.join(str(parent_folder), str(folder)), conf_folder, str(folder))) break if os.path.isfile(path): file = File(dir) is_excluded = True for extension in configuration_folder_structure.all_extensions(): if extension == file.extension(): is_excluded = False break is_excluded_file = False for conf_file in configuration_folder_structure.all_files(): if str(file) == str(conf_file): if conf_file.is_excluded(): is_excluded_file = True break if is_excluded is False and is_excluded_file is False: current_folder.add_file(file) return current_folder