12345678910111213141516171819202122232425262728 |
- import csv
- from pathlib import Path
- def convert_dir(path):
- source_path = Path(path)
- target_path = source_path.parent.joinpath('staging')
- for source_file in source_path.glob('*.csv'):
- print(source_file.name)
- target_file = target_path / source_file.name
- convert_file(source_file, target_file)
- def convert_file(source, target):
- with open(source, 'r', encoding='utf-8') as frh:
- with open(target, 'w', encoding='latin-1') as fwh:
- csv_reader = csv.reader(frh, delimiter=';')
- csv_writer = csv.writer(fwh, delimiter='\t')
- csv_writer.writerows(csv_reader)
- def main():
- convert_dir('E:\\GEBOS\\data')
- if __name__ == '__main__':
- main()
|