<?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 Copy Shapefiles to Geodatabse: How to improve current script in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/batch-copy-shapefiles-to-geodatabse-how-to-improve/m-p/591389#M46367</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Peter,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think slicing can help you in this case. base[:-4] should return everything except the last 4 characters.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 20 May 2012 15:43:06 GMT</pubDate>
    <dc:creator>BruceNielsen</dc:creator>
    <dc:date>2012-05-20T15:43:06Z</dc:date>
    <item>
      <title>Batch Copy Shapefiles to Geodatabse: How to improve current script</title>
      <link>https://community.esri.com/t5/python-questions/batch-copy-shapefiles-to-geodatabse-how-to-improve/m-p/591387#M46365</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Firstly, please note that I'm new to programming and Python. I've created the following Python script to loop through a directory, validate the shapefile names that I then copy to a specified File Geodatabase. The are some shapefiles that have that already have "_shp" attached the shapefile name and the "ValidateTableName" adds "_shp" to the output Feature Class. I have striped out "_shp" before copy the shapefile to the Geodatabase. I have noticed that where the shapefile already had "_shp" it drops an additional character at the end. How to i prevent this from happenning. i.e. citiespop_shp.shp = citispo&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy, os
... arcpy.env.workspace = r"S:\Projects\H108392\H108392.gdb"
... arcpy.env.OverwriteOutput = True
... inWksp = r"S:\Projects\H108392\data_received\KageraMonograph\KAGERA_GIS\_Vector_Data"
... for root, dirs, files in os.walk(inWksp):
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for name in files:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if name.endswith(".shp"):
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; path = os.path.abspath(os.path.join(root, name))
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; base = arcpy.ValidateTableName(os.path.basename(path))
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Processing "+base
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyFeatures_management(path, "S:/Projects/H108392/H108392.gdb/"+base.rstrip("_shp"))&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any advice would be appreciated and as well as any pointers wher I could improve the structure of my code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 20 May 2012 12:28:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/batch-copy-shapefiles-to-geodatabse-how-to-improve/m-p/591387#M46365</guid>
      <dc:creator>PeterWilson</dc:creator>
      <dc:date>2012-05-20T12:28:53Z</dc:date>
    </item>
    <item>
      <title>Re: Batch Copy Shapefiles to Geodatabse: How to improve current script</title>
      <link>https://community.esri.com/t5/python-questions/batch-copy-shapefiles-to-geodatabse-how-to-improve/m-p/591388#M46366</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The error is in the incorrect usage of Python's "rstrip" command. "rstrip" removes ANY occurrences of the characters in the search string you supply (in your case "_shp") from the right side of the processed string. This is why it is going wrong, since "citiespop_shp" contains an additional "p" character as the ending, and since "p", is part of "_shp", it is also removed from "citiespop", resulting in "citiespo". The removing only stops at the "o" character ("citiespo"), as that is the first character not part of the search string "_shp"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Please note that for "rstring", the order of the characters you supply is irrelevant. If you coded:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"teststring.rstring("phs_")"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-style:italic;"&gt;the results would be exactly the same&lt;/SPAN&gt;&lt;SPAN&gt;, e.g. giving you "citiespo" for the processed basename "citiespop_shp"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You will need to use another of Python's string commands to accomplish what you want to do.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 20 May 2012 14:13:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/batch-copy-shapefiles-to-geodatabse-how-to-improve/m-p/591388#M46366</guid>
      <dc:creator>MarcoBoeringa</dc:creator>
      <dc:date>2012-05-20T14:13:39Z</dc:date>
    </item>
    <item>
      <title>Re: Batch Copy Shapefiles to Geodatabse: How to improve current script</title>
      <link>https://community.esri.com/t5/python-questions/batch-copy-shapefiles-to-geodatabse-how-to-improve/m-p/591389#M46367</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Peter,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think slicing can help you in this case. base[:-4] should return everything except the last 4 characters.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 20 May 2012 15:43:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/batch-copy-shapefiles-to-geodatabse-how-to-improve/m-p/591389#M46367</guid>
      <dc:creator>BruceNielsen</dc:creator>
      <dc:date>2012-05-20T15:43:06Z</dc:date>
    </item>
  </channel>
</rss>

