os.makedirs(target_dir, exist_ok=True) record = {}
defget_dir_pdfs(base_dir): global record for i in os.listdir(base_dir): dir_name = os.path.join(base_dir, i) if os.path.isdir(dir_name): get_dir_pdfs(dir_name) elif os.path.isfile(dir_name): if dir_name.lower().endswith(".pdf"): file_name = dir_name.split("/")[-1] if file_name in record: print("ERROR") else: record[file_name] = dir_name shutil.copyfile(dir_name, os.path.join(target_dir, file_name))