ghwest11

IndexError: list index out of range PLEASE HELP

Discussion created by ghwest11 on Jun 19, 2014
Latest reply on Jun 19, 2014 by ghwest11
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)

Outcomes