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
  • 393
  • 5
  • 14

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,306
  • 1
  • 10
  • 24