I have about 500 shapefiles that contain polygons. One polygon in each shapefile. I want to make a new field in their attribute tables called name.

To give you an example the name of each shp has the same formula like "Ikaria_20_09_16". Ikaria is the place and the rest are date. Each shapefile has different name of place and of course different date.

How can I perform an edit where I can take the first word of the name and put it in the field?

In addition I want to make new fields about date but in separate ways. One for day, one for month and one for year. I want also to take the from the name of the shp what I need and put it in field.

Is there any way to do that?

  • Please decide which of ArcPy and ModelBuilder you wish to try and use to do this. That way you will be able to show us where you are stuck with a code snippet or test model. – PolyGeo Feb 28 at 20:22
  • As per the Tour there should be only one question asked per question. – PolyGeo Feb 28 at 20:25
  • I cannot decide which of these because i don't know how it is possible to do. But let's say i choose modelbuilder. Also i am sorry about the length of question. Should be better to split in 2 parts? – Stathis Tsiotsiopoulos Feb 28 at 20:57
  • 2
    "Is it possible?" questions are of limited value, because the answer is nearly always "Yes," and even likely to be "Sure, a couple of ways," neither of which really addresses the how. Unfortunately, we're a problem-solving site, not a tutorial one, so we ask that you make an attempt to solve the task before asking the question, and that you detail what you have attempted and detail what problem was encountered. While a robust solution might run 20 lines of Python, it might be possible to do this with six lines of DA UpdateCursor code, plus one line per field to be updated. – Vince Feb 28 at 21:32
  • I think you should ask only one question here. The answer to that may enable you to answer your second question. – PolyGeo Feb 28 at 21:54

ArcMap ModelBuilder

I created a simple model in ArcMap ModelBuilder that adds the shapefile name as a new field in the shapefile. I assumed that your shapefiles are all in the same folder (Test) and not in sub-folders. If they are also in sub-folders, make sure to set "recursive" in the iterator tool.

  • For the add field tool: make sure the field type is set to TEXT, and that you have a proper amount of characters (like 50).
  • For the Calculate field tool: Expression type should be VB, and the Expression is: "%Name%" (an in-line variable that refers back to the input from the iterator).

After adding the shapefile name to each shapefile. You can simply merge all your shapefiles into shapefile (containing the FolderName field), and export the Attribute Table to Excel. That would be the easiest way to solve the second part of your question, using the Text to Columns function.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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