headers.py 581 B

1234567891011121314151617
  1. import os
  2. from pathlib import Path
  3. def create_headerfiles(base_dir: str):
  4. """opens every *.csv in base_dir and saves first line to subfolder "Kopfzeilen" """
  5. dest = Path(f"{base_dir}\\Kopfzeilen")
  6. os.makedirs(dest, exist_ok=True)
  7. for source_file in Path(base_dir).glob("*.csv"):
  8. dest_file = dest / source_file.name
  9. with source_file.open("r", encoding="latin-1") as frh, dest_file.open("w", encoding="latin-1") as fwh:
  10. fwh.write(frh.readline())
  11. if __name__ == "__main__":
  12. create_headerfiles("C:/GlobalCube/System/OPTIMA/Export")