开发者

How do I add text to multiple filenames using Python?

开发者 https://www.devze.com 2023-03-25 06:30 出处:网络
I have a series of files that I need to add the creation year (2007) to the end of the filename: Currently:

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

精彩评论

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