Skip to content Skip to sidebar Skip to footer

How Do I Add Text To Multiple Filenames Using Python?

I have a series of files that I need to add the creation year (2007) to the end of the filename: Currently: NewZealand_cities.shp NewZealand_roads.shp etc. Need: NewZealand_cities2

Solution 1:

Did you try this:

import os
name, ext = os.path.splitext(fname)
os.rename(fname, name + '2007' + ext)

Post a Comment for "How Do I Add Text To Multiple Filenames Using Python?"