Getting the input file name

726
1
11-14-2011 12:06 PM
RussellKallstrom
New Contributor III
Hi folks-

I need help thinking something through. Basically what I'd like is to have a modified append tool that not only appends multiple the point attribute data, but also "pastes" the inputted shapefile's name(s) to a filename attribute column.  That way I can track where the data came from.  The only way I can think to do this is something along the lines of the following:

for each shp in featureclasses:
  outFeatureClass = os.path.join("C:\GIS\Scripts\temp\temptrks", shp.strip(".shp"))
  arcpy.CopyFeatures_management(shp, outFeatureClass)
  arcpy.AddField_management(outFeatureClass, "filename", "TEXT", "","", "254")
  arcpy.CalculateField_management(outFeatureClass, "filename", 
                                str(shp), "PYTHON")


Then I'd like to append it to a target dataset.

What I'd like to do is be able to have a user drag and drop multiple shapefiles from multiple directories into a Multiple Value input box (like that in the Append tool).

My questions are two:
1) Is there an easier/better way?
2) If not, to what do I set the parameter type (Multiple Value is not a selection).

RK
0 Kudos
1 Reply
RussellKallstrom
New Contributor III
I wanted to clarify my thought process.

#Need to use a for structure so that each input feature class is taken in turn
for each shp in featureclasses:
  #Get the name of the feature class
  outFeatureClass = os.path.join("C:\GIS\Scripts\temp\temptrks", shp.strip(".shp"))
  #Copy and past the feature class to the temporary workspace, to preserve original
  arcpy.CopyFeatures_management(shp, outFeatureClass)
  #Add filename field to the copy
  arcpy.AddField_management(outFeatureClass, "filename", "TEXT", "","", "254")
  #Calculate the filename attribute from the file name
  arcpy.CalculateField_management(outFeatureClass, "filename", 
                                str(shp), "PYTHON")
#Then append each feature class, probably with another for each


It seems a little lengthy, and I'm thinking there's got to be an easier way to capture the filename.
0 Kudos