<?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: &amp;quot;Group layers&amp;quot; by name and merge them with arcpy in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/quot-group-layers-quot-by-name-and-merge-them-with/m-p/306505#M23805</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Johanna,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is a sample that may work:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
from arcpy import env
env.workspace = r"E:\Temp\Python\Data.gdb"

#create list of feature clases
fcList = [fc for fc in arcpy.ListFeatureClasses("*")]

char = []

#append unique first and last character groupings
for fc in fcList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if fc[0] + "_*_" + fc[-1] not in char:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; char.append(fc[0] + "_*_" + fc[-1])

#merge results
for wildCard in char:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; name = wildCard.split("_*_")[0] + wildCard.split("_*_")[-1] + "_merge"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; newfcList = [fc for fc in arcpy.ListFeatureClasses(wildCard)]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Merge_management(newfcList, name)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 14:40:10 GMT</pubDate>
    <dc:creator>JakeSkinner</dc:creator>
    <dc:date>2021-12-11T14:40:10Z</dc:date>
    <item>
      <title>"Group layers" by name and merge them with arcpy</title>
      <link>https://community.esri.com/t5/python-questions/quot-group-layers-quot-by-name-and-merge-them-with/m-p/306504#M23804</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don´t use python that often and I´m kind of new to it. I have a lot af layers in a single folder and I need to merge all the layers that starts and ends with the same character. I´ve done it manually before but it takes too much time to select the layers one by one through the merge tool and I have tried to use python to do it semiautomated, with Listfeatureclasses and wildcards and then continue to merge them, but it was also timeconsuming. It also seems like a waste of time to do it "my way" every time there are new updates.&lt;/P&gt;&lt;P&gt;I have tried to find a solution to my problem online and I searched through forums, but I´ve found nothing yet (maybe I´m searching for the wrong things). Below is a printscreen of a small part of my folder, so there are many more layers starting with other characters than e and h. Can I somehow with python&amp;nbsp; group them and merge those that have the same filetype and characters (not middle characters)? &lt;/P&gt;&lt;P&gt;&lt;IMG alt="printsc.png" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/190744_printsc.png" style="height: auto;" /&gt;&lt;/P&gt;&lt;P&gt;If this question already exist with an answer please let me know &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/grin.png" /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Mar 2016 11:45:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/quot-group-layers-quot-by-name-and-merge-them-with/m-p/306504#M23804</guid>
      <dc:creator>JohannaKollin</dc:creator>
      <dc:date>2016-03-11T11:45:17Z</dc:date>
    </item>
    <item>
      <title>Re: "Group layers" by name and merge them with arcpy</title>
      <link>https://community.esri.com/t5/python-questions/quot-group-layers-quot-by-name-and-merge-them-with/m-p/306505#M23805</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Johanna,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is a sample that may work:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
from arcpy import env
env.workspace = r"E:\Temp\Python\Data.gdb"

#create list of feature clases
fcList = [fc for fc in arcpy.ListFeatureClasses("*")]

char = []

#append unique first and last character groupings
for fc in fcList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if fc[0] + "_*_" + fc[-1] not in char:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; char.append(fc[0] + "_*_" + fc[-1])

#merge results
for wildCard in char:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; name = wildCard.split("_*_")[0] + wildCard.split("_*_")[-1] + "_merge"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; newfcList = [fc for fc in arcpy.ListFeatureClasses(wildCard)]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Merge_management(newfcList, name)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:40:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/quot-group-layers-quot-by-name-and-merge-them-with/m-p/306505#M23805</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-11T14:40:10Z</dc:date>
    </item>
    <item>
      <title>Re: "Group layers" by name and merge them with arcpy</title>
      <link>https://community.esri.com/t5/python-questions/quot-group-layers-quot-by-name-and-merge-them-with/m-p/306506#M23806</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you so much, this worked! &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 14 Mar 2016 06:28:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/quot-group-layers-quot-by-name-and-merge-them-with/m-p/306506#M23806</guid>
      <dc:creator>JohannaKollin</dc:creator>
      <dc:date>2016-03-14T06:28:27Z</dc:date>
    </item>
  </channel>
</rss>

