<?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: Merge all shapefiles in directory for 10.1 in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/merge-all-shapefiles-in-directory-for-10-1/m-p/724386#M56084</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Seems unnecessarily verbose.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy as gp

gp.env.workspace = r"your_input_path"
feature_list = gp.ListFeatureClasses("*.shp", "Polygon")
out_fc = r"your_output_path"
gp.Merge_management(feature_list, out_fc)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 06:58:49 GMT</pubDate>
    <dc:creator>MathewCoyle</dc:creator>
    <dc:date>2021-12-12T06:58:49Z</dc:date>
    <item>
      <title>Merge all shapefiles in directory for 10.1</title>
      <link>https://community.esri.com/t5/python-questions/merge-all-shapefiles-in-directory-for-10-1/m-p/724385#M56083</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am trying to move some scripts from 9.3 over to 10.1 and a portion of my script is hanging up on the merge tool.&amp;nbsp; Below is the code from 9.3 pertaining to the merge (tested and worked).&amp;nbsp; Obviously I set Input_Workspace at run time.&amp;nbsp; The goal is to merge all shapefiles in the directory.&amp;nbsp; All are same type (polygon):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;print "\nSetting the current workspace to: " + Input_Workspace + "...\n"
gp.Workspace = Input_Workspace

# Delete Merge file if exists...
merged_file = Input_Workspace + '/' + "Exp_merged.shp"
if gp.Exists(merged_file):
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Delete(merged_file)
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Merge file exists, deleted...\n"

# Start a blank list for appending
list = []

# For each file in the current directory
for file in os.listdir(Input_Workspace):
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Get files that end with *.shp
&amp;nbsp;&amp;nbsp;&amp;nbsp; if (file.endswith("shp")):

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Append all the files together into one big list
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; filepath = list.append(file)

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Hard-code the output merged shapefile name
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; shapefile = "Exp_merged.shp"

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Given a list of shapefiles, separate each by a ";"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # and put quotes around the whole thing
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; def Lst(filepath):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return '"%s"' % ';'.join(list)

# Set the variable "mergedlist" to the newly formatted list of shapefiles
mergedlist = Lst(filepath)
print "Merging exports...\n"
gp.merge_management(mergedlist, shapefile)
print "Merged " + mergedlist + " to get " + shapefile + "...\n"&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Can anybody help me convert this?&amp;nbsp; I have tried changing the semicolon to a comma (as it appears arcpy merge wants a different format for the input).&amp;nbsp; If you have a better way I am of course open to that.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Sep 2012 14:33:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/merge-all-shapefiles-in-directory-for-10-1/m-p/724385#M56083</guid>
      <dc:creator>ChrisHanes1</dc:creator>
      <dc:date>2012-09-06T14:33:16Z</dc:date>
    </item>
    <item>
      <title>Re: Merge all shapefiles in directory for 10.1</title>
      <link>https://community.esri.com/t5/python-questions/merge-all-shapefiles-in-directory-for-10-1/m-p/724386#M56084</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Seems unnecessarily verbose.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy as gp

gp.env.workspace = r"your_input_path"
feature_list = gp.ListFeatureClasses("*.shp", "Polygon")
out_fc = r"your_output_path"
gp.Merge_management(feature_list, out_fc)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 06:58:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/merge-all-shapefiles-in-directory-for-10-1/m-p/724386#M56084</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-12T06:58:49Z</dc:date>
    </item>
    <item>
      <title>Re: Merge all shapefiles in directory for 10.1</title>
      <link>https://community.esri.com/t5/python-questions/merge-all-shapefiles-in-directory-for-10-1/m-p/724387#M56085</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I will give that a shot.&amp;nbsp; I think I had the merge right in my last attempt, but it gave me a field warning (couldn't populate it with a value).&amp;nbsp; I think that value is simply too long because the length is variable between shapefiles (the process that creates them unfortunately chops the length of text fields to the longest value in it.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, I think I am going to have to scrap the merge and just append them all to a feature class with the correct schema already.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am hoping this works (list is the same value from my previous code, or feature_list in your code):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;AppendTarget = thisGDB + '/' + "Exp_merged"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.Append_management (list, AppendTarget, "NO_TEST")&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Sep 2012 16:55:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/merge-all-shapefiles-in-directory-for-10-1/m-p/724387#M56085</guid>
      <dc:creator>ChrisHanes1</dc:creator>
      <dc:date>2012-09-06T16:55:50Z</dc:date>
    </item>
  </channel>
</rss>

