Iterate through .gdbs not working anymore

248
2
Jump to solution
09-26-2018 08:48 AM
DavidSzczebak
New Contributor

Hi, 
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\exportcontours.py", line 22, in <module>
arcpy.CopyFeatures_management(a, output)
File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\management.py", 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"):
            continue
         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):
               all_fcs.append(fc)

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


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

0 Kudos
1 Solution

Accepted Solutions
DarrenWiens2
MVP Honored Contributor

The error message says output is ".shp" but script says it's ".gdb". Perhaps check script to make it is what you think it is.

Other than that, try setting the overwriteOutput environment to True:

import os
import arcpy
arcpy.env.overwriteOutput = True
...‍‍‍‍‍‍‍‍‍‍‍‍

edit: are you sure this script has ever worked, as written? The second parameter in CopyFeatures should be a feature class, but your script has it as a file geodatabase. See the code samples here for how to use geodatabase feature classes in copy features: Copy Features—Data Management toolbox | ArcGIS Desktop  

View solution in original post

0 Kudos
2 Replies
DarrenWiens2
MVP Honored Contributor

The error message says output is ".shp" but script says it's ".gdb". Perhaps check script to make it is what you think it is.

Other than that, try setting the overwriteOutput environment to True:

import os
import arcpy
arcpy.env.overwriteOutput = True
...‍‍‍‍‍‍‍‍‍‍‍‍

edit: are you sure this script has ever worked, as written? The second parameter in CopyFeatures should be a feature class, but your script has it as a file geodatabase. See the code samples here for how to use geodatabase feature classes in copy features: Copy Features—Data Management toolbox | ArcGIS Desktop  

0 Kudos
DavidSzczebak
New Contributor

Thank you Darren, that's absolutely what it was!

........ I had a path, but no file name for it to write..... 

changed

 arcpy.CopyFeatures_management(a, output)

to:

arcpy.CopyFeatures_management(a, "%s\%s" % (output, a)) 

and it works great