<?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 Name output using input base name (minus extension) in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/name-output-using-input-base-name-minus-extension/m-p/540997#M18008</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi All,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In modelbuilder, I need to use the base name from an input file to name an output later in the process.&amp;nbsp; For example, I have NetCDF files named like A12_G01_X00_ABCABC10.nc.&amp;nbsp; I want to clip the features and name the output using the same name, minus the ".nc" extension. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I can easily use the input filename as an inline variable using %InputFile%.shp, but that produces A12_G01_X00_ABCABC10.nc.shp, which contains an extra period and therefore creates an illegal character.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is it possible to use an inline variable to drop the extension ".nc" and replace it with ".shp".&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Matt Ruch&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;GIS Analyst&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Brown &amp;amp; Caldwell&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 15 Aug 2011 16:28:40 GMT</pubDate>
    <dc:creator>deleted-user-XuRyPg9pv1OY</dc:creator>
    <dc:date>2011-08-15T16:28:40Z</dc:date>
    <item>
      <title>Name output using input base name (minus extension)</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/name-output-using-input-base-name-minus-extension/m-p/540997#M18008</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi All,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In modelbuilder, I need to use the base name from an input file to name an output later in the process.&amp;nbsp; For example, I have NetCDF files named like A12_G01_X00_ABCABC10.nc.&amp;nbsp; I want to clip the features and name the output using the same name, minus the ".nc" extension. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I can easily use the input filename as an inline variable using %InputFile%.shp, but that produces A12_G01_X00_ABCABC10.nc.shp, which contains an extra period and therefore creates an illegal character.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is it possible to use an inline variable to drop the extension ".nc" and replace it with ".shp".&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Matt Ruch&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;GIS Analyst&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Brown &amp;amp; Caldwell&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Aug 2011 16:28:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/name-output-using-input-base-name-minus-extension/m-p/540997#M18008</guid>
      <dc:creator>deleted-user-XuRyPg9pv1OY</dc:creator>
      <dc:date>2011-08-15T16:28:40Z</dc:date>
    </item>
    <item>
      <title>Re: Name output using input base name (minus extension)</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/name-output-using-input-base-name-minus-extension/m-p/540998#M18009</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I should mention that I am using 9.3.1.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Aug 2011 16:50:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/name-output-using-input-base-name-minus-extension/m-p/540998#M18009</guid>
      <dc:creator>deleted-user-XuRyPg9pv1OY</dc:creator>
      <dc:date>2011-08-15T16:50:26Z</dc:date>
    </item>
    <item>
      <title>Re: Name output using input base name (minus extension)</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/name-output-using-input-base-name-minus-extension/m-p/540999#M18010</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Use the Calculate Value tool.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Assuming you have a model variable named "Input Features" and its contents is "E:\Data\Iowa\IowaCo.shp".&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Add the Calculate Value tool to your model.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For the Expression parameter, enter:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;base("%Input Features%")&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;(the name of the variable)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In the Code Block parameter: enter:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def base(filename):
&amp;nbsp; import os
&amp;nbsp; y = os.path.basename(filename)
&amp;nbsp; return y[:y.rfind(".")]&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In the Data Type parameter, set it to String.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The output of Calculate Value ("output_value") by default will contain (when model is run) "IowaCo".&amp;nbsp; You can then use %output_value% to name your file.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:28:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/name-output-using-input-base-name-minus-extension/m-p/540999#M18010</guid>
      <dc:creator>DaleHoneycutt</dc:creator>
      <dc:date>2021-12-11T23:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: Name output using input base name (minus extension)</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/name-output-using-input-base-name-minus-extension/m-p/541000#M18011</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Worked great! Thank you, Dale.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Matt Ruch&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Aug 2011 18:28:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/name-output-using-input-base-name-minus-extension/m-p/541000#M18011</guid>
      <dc:creator>deleted-user-XuRyPg9pv1OY</dc:creator>
      <dc:date>2011-08-15T18:28:04Z</dc:date>
    </item>
    <item>
      <title>Re: Name output using input base name (minus extension)</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/name-output-using-input-base-name-minus-extension/m-p/541001#M18012</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Is it possible to use os.path.split in the Calculate Values tool to extract parts from the base name, where the underscore is the separator for the parts?&amp;nbsp; I will need to use those individual parts to calculate field attributes. Using the example Dale provided above, I would want to use the "Iowa" part of "IowaCo" and calculate a field called [Name] = "Iowa".&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Matt Ruch&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Aug 2011 20:10:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/name-output-using-input-base-name-minus-extension/m-p/541001#M18012</guid>
      <dc:creator>deleted-user-XuRyPg9pv1OY</dc:creator>
      <dc:date>2011-08-15T20:10:03Z</dc:date>
    </item>
    <item>
      <title>Re: Name output using input base name (minus extension)</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/name-output-using-input-base-name-minus-extension/m-p/541002#M18013</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Check out this &lt;/SPAN&gt;&lt;A href="http://blogs.esri.com/Dev/blogs/geoprocessing/archive/2010/08/30/Concatenate.aspx"&gt;blog on Calculate Field&lt;/A&gt;&lt;SPAN&gt;.&amp;nbsp; It shows how to use .split.&amp;nbsp; Although it's about Calculate Field and not Calculate Value, I think you'll get the idea -- a code block w/in Calculate Value that breaks apart a string and returns a new string.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Aug 2011 20:26:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/name-output-using-input-base-name-minus-extension/m-p/541002#M18013</guid>
      <dc:creator>DaleHoneycutt</dc:creator>
      <dc:date>2011-08-15T20:26:56Z</dc:date>
    </item>
    <item>
      <title>Re: Name output using input base name (minus extension)</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/name-output-using-input-base-name-minus-extension/m-p/541003#M18014</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If you're going to be parsing strings a lot you will definitely want to look into &lt;/SPAN&gt;&lt;A href="http://en.wikipedia.org/wiki/Regular_expressions"&gt;regular expressions&lt;/A&gt;&lt;SPAN&gt; (see the &lt;/SPAN&gt;&lt;A href="http://docs.python.org/release/2.6.5/library/re.html"&gt;re module&lt;/A&gt;&lt;SPAN&gt; in Python and the &lt;/SPAN&gt;&lt;A href="http://docs.python.org/release/2.6.5/howto/regex.html"&gt;accompanying "how to" document&lt;/A&gt;&lt;SPAN&gt;).&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Aug 2011 21:17:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/name-output-using-input-base-name-minus-extension/m-p/541003#M18014</guid>
      <dc:creator>LoganPugh</dc:creator>
      <dc:date>2011-08-15T21:17:06Z</dc:date>
    </item>
    <item>
      <title>Re: Name output using input base name (minus extension)</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/name-output-using-input-base-name-minus-extension/m-p/541004#M18015</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Dang! I always forget about the veritable plethora of ESRI blogs out there.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you both for posting very useful links. They will be a tremendous help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Matt Ruch&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Aug 2011 22:20:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/name-output-using-input-base-name-minus-extension/m-p/541004#M18015</guid>
      <dc:creator>deleted-user-XuRyPg9pv1OY</dc:creator>
      <dc:date>2011-08-15T22:20:37Z</dc:date>
    </item>
    <item>
      <title>Re: Name output using input base name (minus extension)</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/name-output-using-input-base-name-minus-extension/m-p/541005#M18016</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have been struggling with filename.split since the last post...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Why does the following Expression and Codeblock return "G16"? When I try return z[0], it returns the path and I want to get "S12." &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;newbase("S12_G16_V00_ULABSH10_00.shp")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;def newbase(filename):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; import os&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; y = os.path.split(filename)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; z = filename.split('_')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; return z[1]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Matt Ruch&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 19 Aug 2011 18:35:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/name-output-using-input-base-name-minus-extension/m-p/541005#M18016</guid>
      <dc:creator>deleted-user-XuRyPg9pv1OY</dc:creator>
      <dc:date>2011-08-19T18:35:25Z</dc:date>
    </item>
    <item>
      <title>Re: Name output using input base name (minus extension)</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/name-output-using-input-base-name-minus-extension/m-p/541006#M18017</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I tried this in a Python interactive window and it worked:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; import os
&amp;gt;&amp;gt;&amp;gt; newbase = r"C:\xxx\yyy\S12_G16_V00_ULABSH10_00.shp"
&amp;gt;&amp;gt;&amp;gt; y = os.path.split(newbase)
&amp;gt;&amp;gt;&amp;gt; print y
('C:\\xxx\\yyy', 'S12_G16_V00_ULABSH10_00.shp')
&amp;gt;&amp;gt;&amp;gt; print y[0]
C:\xxx\yyy
&amp;gt;&amp;gt;&amp;gt; print y[1]
S12_G16_V00_ULABSH10_00.shp
&amp;gt;&amp;gt;&amp;gt; z = y[1].split('_')
&amp;gt;&amp;gt;&amp;gt; print z
['S12', 'G16', 'V00', 'ULABSH10', '00.shp']
&amp;gt;&amp;gt;&amp;gt; print z[0]
S12
&amp;gt;&amp;gt;&amp;gt; &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think your issue is that os.path.filename returns two values?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:28:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/name-output-using-input-base-name-minus-extension/m-p/541006#M18017</guid>
      <dc:creator>DaleHoneycutt</dc:creator>
      <dc:date>2021-12-11T23:28:17Z</dc:date>
    </item>
    <item>
      <title>Re: Name output using input base name (minus extension)</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/name-output-using-input-base-name-minus-extension/m-p/541007#M18018</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you again, Dale.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This has been a difficult entry into Python, but after a few more hours of research and learning, I was able to make this work:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;base("%Output From Clip%")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;def base(filename):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; import os&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; fcName = os.path.basename(filename)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; part = fcName.split('_')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; return part[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I like Python.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Matt Ruch&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 21 Aug 2011 04:50:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/name-output-using-input-base-name-minus-extension/m-p/541007#M18018</guid>
      <dc:creator>deleted-user-XuRyPg9pv1OY</dc:creator>
      <dc:date>2011-08-21T04:50:16Z</dc:date>
    </item>
  </channel>
</rss>

