<?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: How to get just the filename returned using Calculate Field tool in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-get-just-the-filename-returned-using/m-p/219618#M16935</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;My pleasure!&amp;nbsp; ...I know how it is when looking for a simple fix, know it just must exist, but need a hint&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, if you don't mind please, would you mark the question answered?&amp;nbsp; I've just started back participating in these forums, think they're a great resource (I use them too), and you can be my 1st 'correct' or acknowledged-as-useful answer.&amp;nbsp; Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 09 Oct 2012 13:57:28 GMT</pubDate>
    <dc:creator>T__WayneWhitley</dc:creator>
    <dc:date>2012-10-09T13:57:28Z</dc:date>
    <item>
      <title>How to get just the filename returned using Calculate Field tool</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-just-the-filename-returned-using/m-p/219615#M16932</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm sure there is a simple answer to this but I'm not seeing it! I want to populate the field I add with just the file name. The code I have below gives me the entire file path populated into the field I add. How can I extract out just the file name?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy, os, sys, string from arcpy import env from arcpy.sa import*&amp;nbsp; arcpy.CheckOutExtension("Spatial") arcpy.env.overwriteOutput = True&amp;nbsp; # Get input parameters for the Zonal Statistics As Table tool inPath = arcpy.GetParameterAsText(0) zoneField = arcpy.GetParameterAsText(1) rasterList = arcpy.GetParameterAsText(2).split(';') outPath = arcpy.GetParameterAsText(3)&amp;nbsp; for raster in rasterList:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ZonalStatisticsAsTable(inPath, zoneField, raster, outPath) &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(outPath, "RasName", "TEXT") &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(outPath, "RasName", '"'+ raster + '"')&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Oct 2012 12:26:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-just-the-filename-returned-using/m-p/219615#M16932</guid>
      <dc:creator>StacyVentresca</dc:creator>
      <dc:date>2012-10-09T12:26:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to get just the filename returned using Calculate Field tool</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-just-the-filename-returned-using/m-p/219616#M16933</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You've already imported the 'os' python module, so use 'pathname' functions as shown:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The 'basename' function includes the file extension:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;os.path.basename(raster)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can 'nest' functions, e.g., if you want the file name without the ext:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;os.path.splitext(os.path.basename(raster))[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Returns text (and your variable 'raster' is already text), so you should be able to substitute directly into your expression as:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;'"' + os.path.splitext(os.path.basename(raster))[0] + '"'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For documentation see:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://docs.python.org/library/os.path.html"&gt;http://docs.python.org/library/os.path.html&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Oct 2012 13:12:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-just-the-filename-returned-using/m-p/219616#M16933</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2012-10-09T13:12:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to get just the filename returned using Calculate Field tool</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-just-the-filename-returned-using/m-p/219617#M16934</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you very much Wayne! That is exactly what I needed. And thanks for introducing me to the pathname functions.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Oct 2012 13:24:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-just-the-filename-returned-using/m-p/219617#M16934</guid>
      <dc:creator>StacyVentresca</dc:creator>
      <dc:date>2012-10-09T13:24:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to get just the filename returned using Calculate Field tool</title>
      <link>https://community.esri.com/t5/python-questions/how-to-get-just-the-filename-returned-using/m-p/219618#M16935</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;My pleasure!&amp;nbsp; ...I know how it is when looking for a simple fix, know it just must exist, but need a hint&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, if you don't mind please, would you mark the question answered?&amp;nbsp; I've just started back participating in these forums, think they're a great resource (I use them too), and you can be my 1st 'correct' or acknowledged-as-useful answer.&amp;nbsp; Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Oct 2012 13:57:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-get-just-the-filename-returned-using/m-p/219618#M16935</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2012-10-09T13:57:28Z</dc:date>
    </item>
  </channel>
</rss>

