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.
<SPAN class="keyword token">import</SPAN> arcpy lyr <SPAN class="operator token">=</SPAN> r”\\gis\test<SPAN class="punctuation token">.</SPAN>lyr”
layer <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>Layer<SPAN class="punctuation token">(</SPAN>lyr<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> layer<SPAN class="punctuation token">.</SPAN>dataSource
Runtime error Traceback <SPAN class="punctuation token">(</SPAN>most recent call last<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
File <SPAN class="string token">"<string>"</SPAN><SPAN class="punctuation token">,</SPAN> line <SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">in</SPAN> <SPAN class="operator token"><</SPAN>module<SPAN class="operator token">></SPAN>
File <SPAN class="string token">"c:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\arcobjects\_base.py"</SPAN><SPAN class="punctuation token">,</SPAN> line <SPAN class="number token">78</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">in</SPAN> _get<SPAN class="punctuation token">(</SPAN>attr_name<SPAN class="punctuation token">,</SPAN> self<SPAN class="punctuation token">.</SPAN>__class__<SPAN class="punctuation token">.</SPAN>__name__<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
NameError<SPAN class="punctuation token">:</SPAN> The attribute <SPAN class="string token">'dataSource'</SPAN> <SPAN class="keyword token">is</SPAN> <SPAN class="operator token">not</SPAN> supported on this instance of Layer<SPAN class="punctuation token">.</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Is there a clever way to get the full data source for the lyr file?