# CHM = Raster Dataset
# Catchment = Vector Dataset
# Outlet_ID = Polygon_ID with I want to add to the Output of the Raster Split Tool
workspace = Tile_chm_catchment
walk = arcpy.da.Walk(workspace, datatype="RasterDataset", type="TIF")
feature_classes = []
for dirpath, dirnames, filenames in walk:
for filename in filenames:
feature_classes.append(os.path.join(dirpath, filename))
print feature_classes # Output = u'///Data_out/CHM/Tile_chm_catchment\\Tile_chm_catchment_99.TIF
# unicode to string
feature_class_string = [x.encode('UTF8') for x in feature_classes]
# print feature_class_string # Output = '//.../Data_out/CHM/Tile_chm_catchment\\Tile_chm_catchment_99.TIF'
for feature in feature_class_string:
#print feature # Output = //..../Data_out/CHM/Tile_chm_catchment\Tile_chm_catchment_99.TIF
Raster_Number = int(re.findall('\d+', feature)[0]) # Raster_99 would lead to Raster_Number = 99
print Raster_Number # Output = ['99']
## feature_class_string_NoNumber_NoTif = ''.join([i for i in feature if not i.isdigit()]).split(".")
## print feature_class_string_NoNumber_NoTif[0]
feature_class_string_NoNumber = ''.join([i for i in feature if not i.isdigit()])
#print feature_class_string_NoNumber # Output = //.../Data_out/CHM/Tile_chm_catchment\Tile_chm_catchment_.TIF
feature_class_string_NoNumber_NoTif = feature_class_string_NoNumber[:-4]
#print feature_class_string_NoNumber_NoTif # Output = ///Data_out/CHM/Tile_chm_catchment\Tile_chm_catchment_
CHM_Input = feature
oidField = arcpy.Describe(Catchment).oidFieldName
#print oidField
fieldValue = arcpy.da.SearchCursor(Catchment,["OID@","Outlet_ID"],where_clause = '{0} = {1}'.format(arcpy.AddFieldDelimiters(CHM_Input, oidField),Raster_Number)) # ID@ —The value of the ObjectID field fieldValue = arcpy.da.SearchCursor(Catchment,["OID@","Outlet_ID"],where_clause = '{0} = {1}'.format(arcpy.AddFieldDelimiters(CHM_Input, oidField),id)) # ID@ —The value of the ObjectID field
#printfieldValue
Rename_Output = str(feature_class_string_NoNumber_NoTif) + str(fieldValue) + ".tif"
print Rename_Output
arcpy.Rename_management(feature, Rename_Output)