Trying to execute the following script tool to rename all the rasters in a folder to a shorter, but still uniquely identifying, version of the names they already have. I am getting "IndexError: list index out of range", "Failed to execute (Rename). I can't figure out what I need to change for this to work. Any help is appreciated, thanks.
import os
import arcpy
from arcpy import env
RASTER_DIR = 'C:/GIS_Working/QQ/Temp_monthly_means_gridded/'
env.workspace = RASTER_DIR
rasters = arcpy.ListRasters()
for raster in rasters:
fileName, fileExtension = os.path.splitext(raster)
fileNameParts = fileName.split('_')
compactFileName = fileNameParts[1] + fileNameParts[4] + fileExtension
arcpy.Rename_management(raster, compactFileName)