I am using ArcGIS Desktop 10.5 and trying to convert a number of shapefiles into a CSV document.

My current model

Some shapefiles have different column names and the Table to Table tool reads in the first columns within the first shapefile and then applies those names to every shapefile, therefore missing some columns.

For example, shp 1 has columns A B C D, so the tool specifies to convert each column, but the next shp 2 has columns A B C D E F. The tool only prints about A B C D, leaving out E F from the shp 2.

I would like the tool to convert each column for every shapefile, not just the columns from the first shapefile being read in.

  • Are you using any SQL expressions or custom field mapping in the Table to Table tool?
    – Iridium
    May 23, 2018 at 12:18
  • I'm just leaving the defaults in terms of SQL and field mapping. Whatever the tool populates it with, I leave that in there. May 23, 2018 at 12:20
  • Are you open to arcpy solutions? This seems ripe for just a bit of coding.
    – Lovette
    May 23, 2018 at 12:37
  • Very open to ArcPy solutions! May 23, 2018 at 12:48

2 Answers 2


I think the issue, as you described, is that with a ModelBuilder iterator, the later tools in the workflow have their parameters set by the output from the first loop of the iterator. In a for loop in arcpy, each iteration should be independent. So...

import arcpy
from arcpy import env

inFld = ""
arcpy.env.workspace = inFld
outFld = ""

shps = arcpy.ListFeatureClasses()

for shp in shps:
    outName = shp[:-4] #strip .shp from the end of the shapefile tname
    arcpy.TableToTable_conversion (shp, outFld, outName + '.csv')

Table to Table also has the options to populate the Field Map of the output table. In the case that the above does not work, you could read the FieldMap from each shp and then use that FieldMap in TableToTable.

  • This works great thanks! Is there a way to add a wildcard operator and a recursive option to work through subfolders? May 23, 2018 at 14:12
  • 1
    arcpy.ListFeatureClasses() will take wildcards (ArcGIS help page), and you could try use os.walk to recursively work through subfolders. Here's another SE page that may help with the latter link
    – Lovette
    May 23, 2018 at 14:16

Just insert the "Copy Rows" in between the iteration and the "Table to Table" tool, and make sure to set the Field Map as an empty variable like in this picture:

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.