1

I have several file geodatabases I've downloaded from a content provider. A subset of them, which I'm filtering by a couple of strings, have 1 feature dataset within (containing many feature classes) that I'd like to list and copy - at the feature dataset level - into one final geodatabase.

I am running into problems with getting the feature datasets isolated and listed.

Here is my code:

import os, zipfile, arcpy

pathPrefix = "C:\\Incoming"

newPath = '/FINAL'
try:
    os.makedirs(pathPrefix + newPath)
except:
    pass

for f in os.listdir(pathPrefix):
    <DO UNARCHIVING/EXTRACTION HERE>

Here's the part I'm having issues with:

fileFilter = ['_DA_10', '_DB_10']

for path, subdirs, files in os.walk(pathPrefix + newPath):
    for name in subdirs:
        if name.endswith(".gdb"):
            if any(x in name for x in fileFilter):
                print(name) ## This gives me the correct FGDBs I'm looking for
                workspace = os.path.join(pathPrefix, name)
                walk = arcpy.da.Walk(workspace, datatype = "FeatureDataset")
                for dirpath, dirnames, filenames, in walk:
                    for filename in filenames:
                        print filename

It runs, but gives me no feature datasets listed.

  • 1
    A side note, I think you should use os.path.exists rather than a try and except for your path creation. Something like: if not os.path.exists(os.path.join(pathPrefix,newPath)): os.makedirs(os.path.join(pathPrefix,newPath)) – JamesLeversha Sep 23 '16 at 16:10
  • Yes, true, I have fixed that in the original script, thanks – auslander Sep 26 '16 at 17:04
2

What about just using using arcpy.ListDatasets?

...
if any(x in name for x in fileFilter):
    print(name) ## This gives me the correct FGDBs I'm looking for
    arcpy.env.workspace = os.path.join(pathPrefix, name)
    fds = arcpy.ListDatasets("","FEATURE")
    for fd in fds:
        print fd

Then, test the name of the feature dataset to see if its the one you want, if so then copy it. Copying the feature dataset will get you all the FCs in it.

Here's a quick test for setting the workspace and getting FDs, you can do this in the Python window of ArcMap or Catalog:

arcpy.env.workspace = r"full path to fgdb"
arcpy.ListDatasets()
  • yeah, that didn't work, it gave me the error "NoneType object is not iterable" – auslander Sep 23 '16 at 16:51
  • @auslander Make sure your workspace is getting set correctly and you can get back feature datasets, see my edit. – Chad Cooper Sep 23 '16 at 17:22
  • I thought you're only supposed to set the workspace once since it's a global variable? Either way, no matter which way I do it, I get the 'NoneType object is not iterable' error. When I set the env.workspace outside the loop, I get no feature datasets returned. – auslander Sep 26 '16 at 17:02

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.