If you're having issues with shapefile names, a quick script before your merge to find the culprits and make a new copy of the shapefiles will fix the problem. Iterate through each shapefile, test its name, and copy if needed. Merge, then delete whatever new shapefiles you created.
Something like this (untested):
import arcpy
import os
inFeaturesToMerge = [dissolve_1, dissolve_2, dissolve_3, dissolve_4, dissolve_5]
#empty list for merge
mergeFcs = []
#empty list for delete
garbage = []
#iterate feature classes
for fc in inFeaturesToMerge:
#directory of shapefile
shpPath = os.path.dirname (fc)
#set workspace to shapefile directory
arcpy.env.workspace = shpPath
#Get shapefile name
shpName = os.path.basename (fc)
#Check shapefile name to see if it's kosher
if not shpName.lower().replace ("_", "").rstrip (".shp").isalnum():
#Create unique name
uName = arcpy.CreateUniqueName ("file.shp")
#create new shapefile with new legit name
arcpy.CopyFeatures_management (fc, uName)
#add to list to be merged
mergeFcs += [uName]
#add to list to be deleted
garbage += [uName]
else:
#add legit name to merge feature classes
mergeFcs += [fc]
#merge
arcpy.Merge_management(mergeFcs, FinaloutLocation)
#Clean up
for trash in garbage:
arcpy.Delete_mangement (trash)
A faster variation on this script is to use Rename_management
, rename the culprits, and then change the name back after the merge. This one's a bit dangerous though, as if it fails halfway though you'll have lost some file names:
import arcpy
import os
inFeaturesToMerge = [dissolve_1, dissolve_2, dissolve_3, dissolve_4, dissolve_5]
#empty list for merge
mergeFcs = []
#empty dictionary to track renames
nameChangeDi = {}
#iterate feature classes
for fc in inFeaturesToMerge:
#directory of shapefile
shpPath = os.path.dirname (fc)
#set workspace to shapefile directory
arcpy.env.workspace = shpPath
#Get shapefile name
shpName = os.path.basename (fc)
#Check shapefile name to see if it's kosher
if not shpName.lower().replace ("_", "").rstrip (".shp").isalnum():
#Create unique name
uName = arcpy.CreateUniqueName ("file.shp")
#create new shapefile with new legit name
arcpy.Rename_management (fc, uName)
#Add changed name to dictionary
nameChangeDi [uName] = fc
#add to list to be merged
mergeFcs += [uName]
else:
#add legit name to merge feature classes
mergeFcs += [fc]
#merge
arcpy.Merge_management(mergeFcs, FinaloutLocation)
#Rename back changed shapefiles
for newName in nameChangeDi:
arcpy.Rename_management (newName, nameChangeDi [newName])
sample.shp
and it worked fine so do you still need to see other process ?!