import os # Paths to the folders folder_to_check = "./datasets/roboflow/train/labels" folder_with_files = "./datasets/unified/train/labels" files_to_check = set(os.listdir(folder_to_check)) for filename in os.listdir(folder_with_files): file_path = os.path.join(folder_with_files, filename) if filename in files_to_check and os.path.isfile(file_path): try: os.remove(file_path) print(f"Deleted: {file_path}") except Exception as e: print(f"Error deleting {file_path}: {e}")