Yes, you can use a loop to iterate over a list of filenames and perform the extension removal or replacement on each one: import os filenames = ['example1.txt', 'example2.txt', 'example3.txt'] new_extension = '.csv' for filename in filenames: new_filename = filename.replace('.txt', new_extension) os.rename(filename, new_filename)