AnsweredAssumed Answered

Using Python to split and rename file

Question asked by wxguesser26 on Aug 5, 2020
Latest reply on Aug 5, 2020 by wxguesser26

Good afternoon,

I am trying to split a file name and shorten it.  They are .tif files.  The code I am using is:

 

import arcpy
from arcpy import env

env.workspace = "C:\GIS_Projects\VA_1Meter_DEMs\Working_Shapefiles"

in_data = arcpy.ListRasters()
print in_data
for raster in in_data:
part = raster.split("_")
print part
out_data = part[0] + "_" + part[1] + "_" + part[3] + ".tif"
arcpy.Rename_management(in_data, out_data)

 

I am receiving this error:

Traceback (most recent call last):
File "C:/GIS_Projects/Pyth_Code/RenameDem.py", line 12, in <module>
arcpy.Rename_management(in_data, out_data)
File "C:\Program Files (x86)\ArcGIS\Desktop10.7\ArcPy\arcpy\management.py", line 4524, in Rename
raise e
RuntimeError: Object: Error in executing tool

 

The code does print out the raster list in the directory, and also prints out the first raster in the list split, so I know that part is working.  I am stumped where it is supposed to execute the name change though.

Outcomes