123456789101112131415161718192021222324252627 |
- import csv
- from datetime import datetime
- from pathlib import Path
- base_dir = "C:/Projekte/Python"
- # timestamp = date.today().strftime('%Y%m%d')
- def main():
- csv_reader = csv.reader(open(base_dir + "/gctools/DSG_Uebersetzung.csv", "r", encoding="latin-1"), delimiter=";")
- translation = dict([(row[0], row[1]) for row in csv_reader if row[1] != ""])
- target = Path(base_dir + "/export_dsg")
- for filename in Path(base_dir + "/export").glob("*"):
- for old, new in translation.items():
- if "_" + old in filename.name:
- new_name = filename.name.replace(old, new)
- new_timestamp = datetime.fromtimestamp(filename.stat().st_mtime).strftime("%Y%m%d")
- new_name = new_name[:-4] + "_" + new_timestamp + new_name[-4:]
- new_filename = target.joinpath(new_name)
- print(filename.name + " => " + new_filename.name)
- filename.rename(new_filename)
- break
- if __name__ == "__main__":
- main()
|