开发者

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜