0

I have multiple .csv files in the fodler and I need to convert them to .txt files. Currently I am able just to rename them, but I want to leave the original files in place

import os,sys
folder = 'C:....'
for filename in os.listdir(folder):
   infilename = os.path.join(folder,filename)
   if not os.path.isfile(infilename): continue
   oldbase = os.path.splitext(filename)
   newname = infilename.replace('.csv', '.txt')
   output = os.rename(infilename, newname)
akkab
  • 401
  • 1
  • 6
  • 19

1 Answers1

0

You can use the copyfile of shutil.

import shutil

....< part of your code > ...
shutil.copyfile(filename, filename.replace('.csv', '.txt'))
Niels Henkens
  • 2,553
  • 1
  • 12
  • 27