I am trying to batch process KML polygons from a folder into a temp geodatabase. From there, Iif this works and runs then I am trying to Append the polygons to result to a Server connection (Postgres withe append layer). Going to use here the ModelBuilder when the script runs. But I am stuck on a error

Traceback (most recent call last): File "C:\Users\Bjorn.tenBroeke\Documents\Bjorn\KML.py", line 20, in for kml in arcpy.ListFiles('.KM'): TypeError: 'NoneType' object is not iterable Failed to execute (Script).

# Name: BatchKML_to_GDB.py
# Description: Converts a directory of KMLs and copies the output into a single fGDB.
#              A 2 step process: first convert the KML files, and then copy the featureclases

# Import system models
import arcpy, os

# Set workspace (where all the KMLs are)
arcpy.env.workspace= (r"C:\DATA\KML")

# Set local variables and location for the consolidated file geodatabase
outLocation = "C:/WorkingData/fGDBs"
MasterGDB = 'AllKMLLayers.gdb'
MasterGDBLocation = os.path.join(outLocation, MasterGDB)

# Create the master FileGeodatabase
arcpy.CreateFileGDB_management(outLocation, MasterGDB)

# Convert all KMZ and KML files found in the current workspace
for kml in arcpy.ListFiles('*.KM*'):
  print "CONVERTING: " + os.path.join(arcpy.env.workspace,kml)
  arcpy.KMLToLayer_conversion(kml, outLocation)

# Change the workspace to fGDB location
arcpy.env.workspace = outLocation

# Loop through all the FileGeodatabases within the workspace
wks = arcpy.ListWorkspaces('*', 'FileGDB')
# Skip the Master GDB

for fgdb in wks:  

  # Change the workspace to the current FileGeodatabase
  arcpy.env.workspace = fgdb    

  # For every Featureclass inside, copy it to the Master and use the name from the original fGDB  
  featureClasses = arcpy.ListFeatureClasses('*', '', 'Placemarks')
  for fc in featureClasses:
    print "COPYING: " + fc + " FROM: " + fgdb    
    fcCopy = fgdb + os.sep + 'Placemarks' + os.sep + fc    
    arcpy.FeatureClassToFeatureClass_conversion(fcCopy, MasterGDBLocation, fgdb[fgdb.rfind(os.sep)+1:-4])

# Clean up
del kmz, wks, fc, featureClasses, fgdb

2 Answers 2


The error means the workspace folder/directory does not exist (r"C:\DATA\KML"). Check to make sure the "KML" folder/directory exists.


That error indicates that the folder you are calling ListFiles() in has no files matching your wildcard search.

Consequently it is returning None.

Alternatively, try changing:

arcpy.env.workspace= (r"C:\DATA\KML")


arcpy.env.workspace= r"C:\DATA\KML"
  • No error should show if the folder/directory does not contain any like files.
    – artwork21
    Jun 6, 2017 at 11:58
  • @artwork21 I cannot test at the moment but I would expect 'for x in None:' to throw the same error.
    – PolyGeo
    Jun 6, 2017 at 12:02
  • I just tested, no error.
    – artwork21
    Jun 6, 2017 at 12:04

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.