I have a group of shapefiles that are stored in a Windows folder. There are multiple users that will be adding shapefiles to this folder or editing existing shapefiles in this folder on a continual basis. Currently, the shapefiles are manually merged together. I would like to build a very simple model that references all of these shapefiles and merges them on a continuous basis- perhaps 1 time per start of business day. The goal is to have a single layer with all of the shapefiles that is updated automatically as new shapefiles are created. All of the shapefiles created will have the same number of fields, the same field names, and same shape (polygon).
I could use Modelbuilder or possibly create a Python script that runs every morning. I am a beginner with Python.
I am using ArcGIS 10.1.
Update #2- My Python code is as follows:
import arcpy, os, time
arcpy.env.workspace = r'C:\Temp\Planning\Planning_In'
fcs = arcpy.ListFeatureClasses(feature_type='Polygon')
fcOut = r'C:\Temp\Planning\Planning_Out\ProjectMerge.shp'
if fcOut in fcs:fcs.remove(fcOut)
if len(fcs) > 0:
if arcpy.Exists(fcOut):
fcArchived = os.path.join(r'C:\Temp\Planning\Planning_Out', 'Archived_{}.shp'.format(time.strftime('%Y%m%d')))
os.makedirs(os.path.dirname(fcArchived))
arcpy.Copy_management(fcOut, fcArchived)
arcpy.Delete_management(fcOut)
arcpy.Merge_management(fcs, fcOut)
print fcs
My shapefiles are named: 13_012, 13_013, etc.
*** My error message is:
Traceback (most recent call last):
File "C:\Temp\Planning\import arcpy.py", line 16, in <module>
arcpy.Merge_management(fcs, fcOut)
File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\management.py", line 4221, in Merge
raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Datasets: Dataset C:\Temp\Planning\Planning_In\13-004.shp;C:\Temp\Planning\Planning_In\1314-004.shp does not exist or is not supported
Failed to execute (Merge).
Additionally, when I remove the merge and just apply the following code, I receive an error message that 'fcArchived' is not defined:
import arcpy, os, time
arcpy.env.workspace = r'C:\Temp\Planning\Planning_In'
fcs = arcpy.ListFeatureClasses(feature_type='Polygon')
fcOut = r'C:\Temp\Planning\Planning_Out\ProjectMerge.shp'
if fcOut in fcs:fcs.remove(fcOut)
if len(fcs) > 0:
if arcpy.Exists(fcOut):
fcArchived = os.path.join(r'C:\Temp\Planning\Planning_Out', 'Archived_{}.shp'.format(time.strftime('%Y%m%d')))
os.makedirs(os.path.dirname(fcArchived))
arcpy.Copy_management(fcOut, fcArchived)
print fcArchived