<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Using Python to split and rename file in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/using-python-to-split-and-rename-file/m-p/705308#M54584</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It appears the code is failing on the first raster in the loop.&amp;nbsp; Can you provide the name of that raster, so we can see how you are setting out_data.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 05 Aug 2020 15:56:53 GMT</pubDate>
    <dc:creator>JoshuaBixby</dc:creator>
    <dc:date>2020-08-05T15:56:53Z</dc:date>
    <item>
      <title>Using Python to split and rename file</title>
      <link>https://community.esri.com/t5/python-questions/using-python-to-split-and-rename-file/m-p/705307#M54583</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Good afternoon,&lt;/P&gt;&lt;P&gt;I am trying to split a file name and shorten it.&amp;nbsp; They are .tif files.&amp;nbsp; The code I am using is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;from arcpy import env&lt;/P&gt;&lt;P&gt;env.workspace = "C:\GIS_Projects\VA_1Meter_DEMs\Working_Shapefiles"&lt;/P&gt;&lt;P&gt;in_data = arcpy.ListRasters()&lt;BR /&gt;print in_data&lt;BR /&gt;for raster in in_data:&lt;BR /&gt; part = raster.split("_")&lt;BR /&gt; print part&lt;BR /&gt; out_data = part[0] + "_" + part[1] + "_" + part[3] + ".tif"&lt;BR /&gt; arcpy.Rename_management(in_data, out_data)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am receiving this error:&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;BR /&gt; File "C:/GIS_Projects/Pyth_Code/RenameDem.py", line 12, in &amp;lt;module&amp;gt;&lt;BR /&gt; arcpy.Rename_management(in_data, out_data)&lt;BR /&gt; File "C:\Program Files (x86)\ArcGIS\Desktop10.7\ArcPy\arcpy\management.py", line 4524, in Rename&lt;BR /&gt; raise e&lt;BR /&gt;RuntimeError: Object: Error in executing tool&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp; I am stumped where it is supposed to execute the name change though.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Aug 2020 15:45:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-python-to-split-and-rename-file/m-p/705307#M54583</guid>
      <dc:creator>JamesWhite5</dc:creator>
      <dc:date>2020-08-05T15:45:47Z</dc:date>
    </item>
    <item>
      <title>Re: Using Python to split and rename file</title>
      <link>https://community.esri.com/t5/python-questions/using-python-to-split-and-rename-file/m-p/705308#M54584</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It appears the code is failing on the first raster in the loop.&amp;nbsp; Can you provide the name of that raster, so we can see how you are setting out_data.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Aug 2020 15:56:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-python-to-split-and-rename-file/m-p/705308#M54584</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2020-08-05T15:56:53Z</dc:date>
    </item>
    <item>
      <title>Re: Using Python to split and rename file</title>
      <link>https://community.esri.com/t5/python-questions/using-python-to-split-and-rename-file/m-p/705309#M54585</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;USGS_1m_x27y430_VA_Fairfax_County_2018.tif is the name of the first raster.&amp;nbsp; All of the files folow the same format.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Aug 2020 16:35:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-python-to-split-and-rename-file/m-p/705309#M54585</guid>
      <dc:creator>JamesWhite5</dc:creator>
      <dc:date>2020-08-05T16:35:09Z</dc:date>
    </item>
    <item>
      <title>Re: Using Python to split and rename file</title>
      <link>https://community.esri.com/t5/python-questions/using-python-to-split-and-rename-file/m-p/705310#M54586</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I did make a mistake in my code, but that isn't the issue. I put part[3] and changed it to part[2], so it should be parts 0, 1 and 2.&amp;nbsp; I printed out the out_data just now as well, and it prints out the file name I want it to be.&amp;nbsp; It is failing at the Rename.management part of the script for some reason.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Aug 2020 17:36:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-python-to-split-and-rename-file/m-p/705310#M54586</guid>
      <dc:creator>JamesWhite5</dc:creator>
      <dc:date>2020-08-05T17:36:12Z</dc:date>
    </item>
    <item>
      <title>Re: Using Python to split and rename file</title>
      <link>https://community.esri.com/t5/python-questions/using-python-to-split-and-rename-file/m-p/705311#M54587</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I should have caught this earlier, you are passing the wrong object to Rename.&amp;nbsp; Your current code is passing a list of rasters, not a single raster.&amp;nbsp; The line should read:&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Rename_management&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;raster&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; out_data&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Aug 2020 18:40:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-python-to-split-and-rename-file/m-p/705311#M54587</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2020-08-05T18:40:46Z</dc:date>
    </item>
    <item>
      <title>Re: Using Python to split and rename file</title>
      <link>https://community.esri.com/t5/python-questions/using-python-to-split-and-rename-file/m-p/705312#M54588</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ahhh, yes, that works like it should!&amp;nbsp; Thank you so much for that.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Aug 2020 18:55:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-python-to-split-and-rename-file/m-p/705312#M54588</guid>
      <dc:creator>JamesWhite5</dc:creator>
      <dc:date>2020-08-05T18:55:39Z</dc:date>
    </item>
  </channel>
</rss>

