AnsweredAssumed Answered

Iterate through .gdbs not working anymore

Question asked by davidsesri on Sep 26, 2018
Latest reply on Sep 26, 2018 by davidsesri

Had a basic script to iterate through a folder, containing subfolders, then geodatabases, to extract feature classes with a specified name, then append that feature class into a new geodatabase.  Worked fine for a bunch of point features, then tried it for a series of line features, and it keeps breaking with


Traceback (most recent call last):
File "C:\proj\bathy\code\", line 22, in <module>
arcpy.CopyFeatures_management(a, output)
File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\", line 2586, in CopyFeatures
raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000725: Output Feature Class: Dataset W:\Gisdata\Fish\Proj\Bathymetry\contourmrg.shp already exists.
Failed to execute (CopyFeatures)


I don't know where this offending shapefile is coming from!  Help......


Script is as follows:

import os
import arcpy

top_folder = r"W:\Gisdata\Fish\Proj\Bathymetry"
output = r"W:\Gisdata\Fish\Proj\Bathymetry\contourmrg.gdb"
contlist = [ ]

for path, dirs, files in os.walk(top_folder):
   for d in dirs:
         if not d.endswith(".gdb"):
         gdb_path = os.path.join(path, d)

         arcpy.env.workspace = gdb_path
         all_fcs = arcpy.ListFeatureClasses()
         for fds in arcpy.ListDatasets('','feature'):
         for fc in arcpy.ListFeatureClasses('','',fds):

for a in all_fcs:
      if a.endswith('contour'):
           arcpy.CopyFeatures_management(a, output)
            print "Exported %s" % a

print "Exported the following feature classes %s" % contlist