<?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: Batch add field, calculate field as filename in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/batch-add-field-calculate-field-as-filename/m-p/480957#M16151</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Thank you both.&amp;nbsp; This was a huge time saver. Really wish I was more comfortable with scripting tools. The time I could have saved.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Take a look at the following training courses you can take:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://training.esri.com/gateway/index.cfm?fa=catalog.webCourseDetail&amp;amp;courseid=2520"&gt;http://training.esri.com/gateway/index.cfm?fa=catalog.webCourseDetail&amp;amp;courseid=2520&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://training.esri.com/gateway/index.cfm?fa=catalog.webCourseDetail&amp;amp;courseid=2114"&gt;http://training.esri.com/gateway/index.cfm?fa=catalog.webCourseDetail&amp;amp;courseid=2114&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://training.esri.com/gateway/index.cfm?fa=catalog.webCourseDetail&amp;amp;courseid=2143"&gt;http://training.esri.com/gateway/index.cfm?fa=catalog.webCourseDetail&amp;amp;courseid=2143&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://training.esri.com/gateway/index.cfm?fa=catalog.courseDetail&amp;amp;CourseID=50131064_10.x"&gt;http://training.esri.com/gateway/index.cfm?fa=catalog.courseDetail&amp;amp;CourseID=50131064_10.x&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 08 Jan 2014 10:26:54 GMT</pubDate>
    <dc:creator>JakeSkinner</dc:creator>
    <dc:date>2014-01-08T10:26:54Z</dc:date>
    <item>
      <title>Batch add field, calculate field as filename</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/batch-add-field-calculate-field-as-filename/m-p/480953#M16147</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;So here is my last and final question and unfortunately my largest hurdle.&amp;nbsp; I have a tonne of shapefiles (4249 to be exact).&amp;nbsp; I have never used a model builder or scripted anything.&amp;nbsp; I need to somehow batch add a field (named RTENO) and assign the shapefile name to that field.&amp;nbsp; The only other option I have is to batch calculate field with file name one at a time over 4000 times. If anyone knows of anything I could do to make this possible it would be a life saver.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Jan 2014 20:06:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/batch-add-field-calculate-field-as-filename/m-p/480953#M16147</guid>
      <dc:creator>JasonDaniels</dc:creator>
      <dc:date>2014-01-02T20:06:19Z</dc:date>
    </item>
    <item>
      <title>Re: Batch add field, calculate field as filename</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/batch-add-field-calculate-field-as-filename/m-p/480954#M16148</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I were you, I would use model buider and do the following:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. Use iterator to read the feature classes that you would like to run. While excuting iterator, model builder will generate a system variable (it should originally show up as 'Name' in iterator), which stores the file name. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2. Use Add Field tool to add field.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;3. Use Calculate field. This is when you need to use that system variable, use %Name% to get the feature class' name,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help../index.html#/A_quick_tour_of_using_iterators_for_iteration_Looping/002w0000001w000000/"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help../index.html#/A_quick_tour_of_using_iterators_for_iteration_Looping/002w0000001w000000/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helps!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 04 Jan 2014 18:29:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/batch-add-field-calculate-field-as-filename/m-p/480954#M16148</guid>
      <dc:creator>YichiLiu1</dc:creator>
      <dc:date>2014-01-04T18:29:05Z</dc:date>
    </item>
    <item>
      <title>Re: Batch add field, calculate field as filename</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/batch-add-field-calculate-field-as-filename/m-p/480955#M16149</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Jason,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is a script you can run:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
from arcpy import env
env.workspace = r"C:\DATA"

for shapefile in arcpy.ListFeatureClasses("*"):
&amp;nbsp;&amp;nbsp;&amp;nbsp; name = shapefile.split(".")[0]
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(shapefile, "RTENO", "TEXT")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(shapefile, "RTENO", '"' + name + '"', "PYTHON")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You will just need to change the 'env.workspace' to the directory path of your shapefiles.&amp;nbsp; Don't forget to include the 'r' before the path.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:12:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/batch-add-field-calculate-field-as-filename/m-p/480955#M16149</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-11T21:12:59Z</dc:date>
    </item>
    <item>
      <title>Re: Batch add field, calculate field as filename</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/batch-add-field-calculate-field-as-filename/m-p/480956#M16150</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you both.&amp;nbsp; This was a huge time saver. Really wish I was more comfortable with scripting tools. The time I could have saved.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Jan 2014 10:17:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/batch-add-field-calculate-field-as-filename/m-p/480956#M16150</guid>
      <dc:creator>JasonDaniels</dc:creator>
      <dc:date>2014-01-08T10:17:51Z</dc:date>
    </item>
    <item>
      <title>Re: Batch add field, calculate field as filename</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/batch-add-field-calculate-field-as-filename/m-p/480957#M16151</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Thank you both.&amp;nbsp; This was a huge time saver. Really wish I was more comfortable with scripting tools. The time I could have saved.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Take a look at the following training courses you can take:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://training.esri.com/gateway/index.cfm?fa=catalog.webCourseDetail&amp;amp;courseid=2520"&gt;http://training.esri.com/gateway/index.cfm?fa=catalog.webCourseDetail&amp;amp;courseid=2520&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://training.esri.com/gateway/index.cfm?fa=catalog.webCourseDetail&amp;amp;courseid=2114"&gt;http://training.esri.com/gateway/index.cfm?fa=catalog.webCourseDetail&amp;amp;courseid=2114&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://training.esri.com/gateway/index.cfm?fa=catalog.webCourseDetail&amp;amp;courseid=2143"&gt;http://training.esri.com/gateway/index.cfm?fa=catalog.webCourseDetail&amp;amp;courseid=2143&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://training.esri.com/gateway/index.cfm?fa=catalog.courseDetail&amp;amp;CourseID=50131064_10.x"&gt;http://training.esri.com/gateway/index.cfm?fa=catalog.courseDetail&amp;amp;CourseID=50131064_10.x&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Jan 2014 10:26:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/batch-add-field-calculate-field-as-filename/m-p/480957#M16151</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2014-01-08T10:26:54Z</dc:date>
    </item>
    <item>
      <title>Re: Batch add field, calculate field as filename</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/batch-add-field-calculate-field-as-filename/m-p/1145071#M26192</link>
      <description>&lt;P&gt;Hi, i know it's an old conversation but you don't know why it doesn't work for me?&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;var AL016 = "MS_FT_AL016_T";
 var typObjektu = "TYP_OBJEKTU";
                var NF103 = "MS_FT_NF103_T";
                var NF109 = "MS_FT_NF109_T";
                var NF121 = "MS_FT_NF121_T";
                var NF127 = "MS_FT_NF127_T";
                var NF128 = "MS_FT_NF128_T";
                var FTJmeno = "MS_FT_JMENO_P_T";
List&amp;lt;string&amp;gt; names = new List&amp;lt;string&amp;gt;();
                names.Add(AL016);
                names.Add(NF103);
                names.Add(NF109);
                names.Add(NF121);
                names.Add(NF127);
                names.Add(NF128);
 names.Add(FTJmeno);
                foreach (var name in names)
                {
                    FeatureLayer featureLayer = mv.Map.FindLayers(name).First() as FeatureLayer;
                    FeatureClass fc = featureLayer.GetTable() as FeatureClass;
                    await AddField(fc, typObjektu, "TEXT", "", "", 10);
                    object[] paraList = { fc, typObjektu, '"' + name + '"' }; //always comes NULL in the column
                    await StartATask("management.CalculateField", paraList);
                }&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 17 Feb 2022 09:32:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/batch-add-field-calculate-field-as-filename/m-p/1145071#M26192</guid>
      <dc:creator>DavidMrázek</dc:creator>
      <dc:date>2022-02-17T09:32:57Z</dc:date>
    </item>
    <item>
      <title>Re: Batch add field, calculate field as filename</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/batch-add-field-calculate-field-as-filename/m-p/1280046#M26833</link>
      <description>&lt;P&gt;Does this work for Ratsers too?&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't think, with a few changes, where the feature classes are mentioned, I denoted Rasters - but nothing works!!!&lt;/P&gt;&lt;P&gt;Also, the simple %name% - doesn't work!!&lt;/P&gt;</description>
      <pubDate>Wed, 19 Apr 2023 04:48:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/batch-add-field-calculate-field-as-filename/m-p/1280046#M26833</guid>
      <dc:creator>GirijaKalyani</dc:creator>
      <dc:date>2023-04-19T04:48:36Z</dc:date>
    </item>
  </channel>
</rss>

