zhengniu

Merge multiple shapefiles by name consists of characters and numbers

Discussion created by zhengniu on Feb 22, 2012
Latest reply on Feb 22, 2012 by zhengniu
Hi, all
please help to modify following script. Thanks a lot

import arcpy
import os

path ='C:\TempArcGISCalculate\TempFile\ResultsofSplitbyAttributeOIDCopy'
arcpy.env.overwriteOutput = True
arcpy.env.workspace = path
fclist = arcpy.ListFeatureClasses()

i=1
while i in range (1,68):
    blist = []
    for fc in fclist:
        if (fc.endswith(int(i)+'.shp')):
            # Append all files satisfied if condition together into one list
            filepath = blist.append(fc)
            #Output merged shapefile name
            shapefile = 'Tile'+int(i)+'.shp'
            def shplist(filepath):
                return '"%s"' % ';'.join(blist)
    mergedlist = shplist(filepath)
    arcpy.Merge_management(mergedlist, shapefile)
    i = i +1



Problem Statement:
There are 624 point shapefiles saved in one folder. As shown in attached image, the file name is made up of char and numeric. What I want is to merge them according to the numerical value. The numerical value range is from 1 to 67, which represent that there are 67 tiles.
For example: these shapefiles (Apr4m0002.shp, FebI4m0002.shp, FebII4m0002.shp, JanI4m0002.shp, JanII4m0002.shp, ...) will be merged into one shapefile named as Tile2.shp.

The above script is only working for the numerical value in shapefile over 10. when the numerical value is less than 10. the merged shapefile will contains all original shapefiles whose suffix contains the same numerical value.
For example, in addition to shapefiles  (Apr4m0002.shp, FebI4m0002.shp, FebII4m0002.shp, JanI4m0002.shp, JanII4m0002.shp, ...), files (Apr4m0012.shp, Apr4m0022.shp,Apr4m0032.shp, Apr4m0042.shp, Apr4m0052.shp, Apr4m0062.shp, FebI4m0012.shp, FebI4m0022.shp, FebI4m0032.shp, FebI4m0042.shp, FebI4m0052.shp, FebII4m0022.shp, JanI4m0032.shp, JanII4m0042.shp, ...) are also merged into the same shapfile "Tile2.shp"


When the numerical value is larger than 10, it works well. All files whose file name has same value are merged into one shapefile
For example, (Apr4m0022.shp, FebI4m0022.shp, FebII4m0022.shp, JanI4m0022.shp, JanII4m0022.shp,...) are merged into "Tile22.shp"

Attachments

Outcomes