Adding extension to multiple files (Python3.5)

Viewed 8361

I have a bunch of files that do not have an extension to them.

file needs to be file.txt

I have tried different methods (didn't try the complicated ones since I am just learning to do a bit of advanced python).

here is one that I tried:

import os
pth = 'B:\\etc'
os.chdir(pth)
for files in os.listdir('.'):
  changeName = 'files{ext}'.format(ext='.txt')

I tried the append, replace and rename methods as well and it didn't work for me. or those don't work in the 1st place with what I am trying to do?

What am I missing or doing wrong?.

1 Answers
Related