I'm trying to get the data source from a bunch of lyr files pointing to various raster formats. Using the lyr.dataSource method on a feature layer after creating a layer object I can get the data source for TIFs fine but Esri GRID format rasters are seen as being directories. My goal is to re-path the lyr files to the same raster that has been copied to another location using the lyr.replaceDatasource method.
import arcpy lyr = r”\\gis\test.lyr”
layer = arcpy.mapping.Layer(lyr)
Runtime error Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\arcobjects\_base.py", line 78, in _get(attr_name, self.__class__.__name__))
NameError: The attribute 'dataSource' is not supported on this instance of Layer.
Is there a clever way to get the full data source for the lyr file?