import os
path = r'C:\Users\zsqhndn\Desktop\DPF test\5h300test\XSHG'

files = os.listdir(path)

for file in files: 

    index=file.find('.XSHG.hXSHG.h5')
    
    oldname=path+'/'+file
    
    newname=path+'/'+file[0:index]+'XSHG'+'.h5'
    
    os.rename(oldname,newname)
    print(oldname,'======>',newname)
    
