import os

def dosya_uzantilarini_degistir(cur_dir, old_ext, new_ext, sub_dirs=False):
    if sub_dirs:
        for root, dirs, files in os.walk(cur_dir):
            for dosya in files:
                file_ext = os.path.splitext(dosya)[1]
                if old_ext == file_ext:
                    oldname = os.path.join(root, dosya)
                    newname = oldname.replace(old_ext, new_ext)
                    os.rename(oldname, newname)
    else:
        files = os.listdir(cur_dir)
        for dosya in files:
            file_ext = os.path.splitext(dosya)[1]
            if old_ext == file_ext:
                newfile = dosya.replace(old_ext, new_ext)
                os.rename(dosya, newfile)




dosya_uzantilarini_degistir('/home/user/klasorlerim', '.txt', '.html')


dosya_uzantilarini_degistir('/home/user/klasorlerim', '.txt', '.html', True)