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_cities2007.shp NewZealand_roads2007.shp
I have been abl开发者_高级运维e to remove segments of text but cannot add for some reason. Any help would be much appreciated. Thanks.
Did you try this:
import os
name, ext = os.path.splitext(fname)
os.rename(fname, name + '2007' + ext)
精彩评论