def batch_rename(work_dir, old_ext, new_ext):
 for filename in os.listdir(work_dir):
  file_ext = os.path.splitext(filename)[1]
  if (old_ext == file_ext):
   name_list = list(filename)
   name_list[(len(name_list) - len(old_ext)):] = list(new_ext)
   newfile = ''.join(name_list)
   os.rename(os.path.join(work_dir, filename), os.path.join(work_dir, newfile))

def batch_rename ( work_dir , old_ext , new_ext ) : for filename in os . listdir ( work_dir ) : file_ext = os . path . splitext ( filename ) [ 1 ] if ( old_ext == file_ext ) : name_list = list ( filename ) name_list [ ( len ( name_list ) - len ( old_ext ) ) : ] = list ( new_ext ) newfile = '' . join ( name_list ) os . rename ( os . path . join ( work_dir , filename ) , os . path . join ( work_dir , newfile ) )
this will batch rename a group of files in a given directory .