I'm using a script to list datasets from multiple gdbs in ArcPy (to rename most datasets and gdbs). Which looks like this:

dir_gdbs = 'D:\\mypath'

lista_gdbs = glob.glob('*.gdb')
for i in lista_gdbs:
    gdb = (os.path.join(dir_gdbs,i))
    arcpy.env.workspace = gdb
    lista_capas = arcpy.ListDatasets()
    for u in lista_capas:
        #do stuff

It works correctly but there are many gdbs to process and it is very slow. Most of its time is lost changing the workspace (arcpy.env.workspace = gdb). Is there any way to list the datasets within each gdb without doing this?

  • 1
    I'd try arcpy.da.Walk() in place of glob. – PolyGeo Sep 25 '19 at 11:16
  • 1
    @PolyGeo I did't know that function, I'll try it! – gacero Sep 25 '19 at 11:53

I finally used arcpy.da.walk() as PolyGeo suggested.

walk = arcpy.da.Walk(dir_gdbs)
for gdb, x, capas in walk:
    for capa in capas:
        dir, gdb = os.path.split(gdb)
        #do stuff 

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.