You are on page 1of 1

import os

import arcpy
from arcpy import env

# directory containing rasters to be renamed


RASTER_DIR = 'D:\GIS_FILE\CHIRPS\BIL'

env.workspace = RASTER_DIR
for raster in arcpy.ListRasters():

# get the raster name and file extension


fileName,fileExtension = os.path.splitext(raster)

# do some shenanigans to rename the file


# based on your sample raster name, fileNameParts would look like
# fileNameParts[0] = data
# fileNameParts[1] = 1981
# fileNameParts[2] = 01
# fileNameParts[3] = tiff

fileNameParts = fileName.split('.')
compactFileName = fileNameParts[0] + fileNameParts[1] + fileNameParts[2] +
fileExtension

arcpy.Rename_management(raster,compactFileName)

You might also like