1

I would like to select only newly created shapefile (today's). Every time new shapefiles are created from Trimble pathfinder office which I need to upload to ArcGIS server feature class.

Model below iterates all shapefiles and appends but I need to append only newly created so as not to duplicate the data.

Feature class iteration then append

2 Answers 2

2

This Python script will append shapefiles modified since yesterday to a target fc (I'm not sure if this is what you are after):

import arcpy, os, datetime

#workspaces
workspace = r'D:\Kartdata\tk_riks_Sweref_99_TM_shape\terrang'
targetfc = r'D:\Kartdata\test123.shp'

#Function that return modification date of files
def modification_date(filename):
    t = os.path.getmtime(filename)
    return datetime.date.fromtimestamp(t)

#Lists all shapefiles in workspace including paths
lista = [os.path.join(dirpath,f)
    for dirpath, dirnames, files in os.walk(workspace)
    for f in files if f.endswith('.shp')]

#Create new list from list above inluding only those modified since yesterday
modlist = []
for shapefile in lista:
    if modification_date(shapefile) > datetime.date.fromordinal(datetime.date.today().toordinal()-1):
        modlist.append(shapefile)

#Append modified shapefiles to target fc
arcpy.Append_management(inputs=modlist, target=targetfc)
1

Might I suggest adding an additional process to your model like Delete, so as to remove the shapefile after you have successfully appended it? That way, at any given moment only new shapefiles will be in your workspace when you run the model. Since you are using Pathfinder Office you can at any time recreate the shapefiles if needed

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.