0

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 able to remove segments of text but cannot add for some reason. Any help would be much appreciated. Thanks.

3
  • os.rename not working for you? ...maybe show us what you have Commented Aug 2, 2011 at 17:04
  • Can you show us what you've come up with thus far? It's hard to point you in the right direction, when we don't know what you have tried. Commented Aug 2, 2011 at 17:04
  • Please provide more information. What do you mean that you haven't been able to add text to the filenames? Are you using the move/rename function in the OS module? Commented Aug 2, 2011 at 17:06

1 Answer 1

3

Did you try this:

import os
name, ext = os.path.splitext(fname)
os.rename(fname, name + '2007' + ext)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.