I am trying to merge files starting with same 2 characters as below;
- 11111 - merge (output name : 11.shp)
- 11112 - merge (output name : 11.shp)
- 11113 - merge (output name : 11.shp)
- 22112 - merge (output name : 22.shp)
- 22153 - merge (output name : 22.shp)
But my python script' result merge together if "11" is including in the filenames(like 4)). I only want 11***.shp(1)~3)) but A Script merges 11.shp (merge 1~4 as 11.shp)
========================================================================
import sys, os, arcpy, fnmatch
reload(sys)
arcpy.env.workspace = r"F:\a"
workspace = arcpy.env.workspace
outdir = r"F:\b"
List = []
for dirpath, dirnames, filenames in os.walk(workspace, topdown=True):
for filename in filenames:
List.append(os.path.join(dirpath, filename))
break
patterns = set([os.path.basename(fl)[:2] for fl in List])
for pattern in patterns:
group = [fl for fl in List if fnmatch.fnmatchcase(fl, '*' + pattern + '*.shp')]
output = os.path.join(outdir, pattern)
arcpy.Merge_management(group, output)
========================================================================
How can I fix it?