How can I rename the following files:
abc_2000.jpg
abc_2001.jpg
abc_2004.jpg
abc_2007.jpg
into the following ones:
year_2000.jpg
year_2001.jpg
year_2004.jpg
year_2007.jpg
The related code is:
import os
import glob
files = glob.glob('abc*.jpg')
for file in files:
os.rename(file, '{}.txt'.format(???))
Because I have done something similar today:
# By changing one line in code i think this line will work or may be without changing anything this will work
Call the function by passing two arguments f_path as your path and new_name as you like to give to file.
The one line can be broken to:
Here is my solution which is written with comments for each step so that even a newbie can understand and use, hack, and customize:
https://github.com/JerusalemProgramming/PythonAutomatedRenamingOfFilenames/blob/master/program_FileRenameJPEGS.py