from __future__ import annotations import csv from typing import Dict, Iterable, List FIELDNAMES = [ "name", "relative_path", "extension", "size", "creation_date", "modified_date", "hash_value", "file_type", "number_of_files", "volume_name", ] def write_records_csv(path: str, records: Iterable[Dict[str, object]]) -> None: records_list: List[Dict[str, object]] = list(records) with open(path, "w", newline="", encoding="utf-8") as f: writer = csv.DictWriter(f, fieldnames=FIELDNAMES) writer.writeheader() for r in records_list: writer.writerow(r)