Welcome, guest | Sign In | My Account | Store | Cart

Quick and dirty Pytyon 2.7.5 script that prints a catalog of non-empty features and tables within a file-gdb or folder of mdb's using ArcGIS 10.1's arcpy library.

Python, 48 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import arcpy as ap, os, sys, time, Tkinter as Tk, tkFileDialog
from arcpy import env

def SelectFolder(req = 'Please select a fgdb:'):
    """ Customizable folder selection dialogue, changes current directory to and returns mypath. """
    try:
        root = Tk.Tk(); root.withdraw(); mypath = tkFileDialog.askdirectory(initialdir="C:\\", title=req); root.destroy()
        os.chdir(mypath)
        return mypath
    except:
        print "Error in folder selection:", sys.exc_info()[1]; time.sleep(5);  sys.exit()

# Set workspace
gdb_type = raw_input('Do you want to open a fgdb or dbf (f/d): ')

if gdb_type == 'd':
    import glob
    dbf_folder = SelectFolder("Please select a folder or dbf's:")
    tic = time.clock()
    print dbf_folder, "DBF's:"
    for table in glob.iglob(dbf_folder+"/*.dbf"):
        numrec = int(ap.GetCount_management(table).getOutput(0))
        if numrec > 0:  print ' -{0}: {1} records'.format(table.split('\\')[1], numrec)
    print 'This arcpy cataloging took {} sec.'.format(str(time.clock()-tic)[:8])
else:
    env.workspace = SelectFolder()
    tic = time.clock()
    # Loop through root fc's:
    print "{}\nRoot FC's:".format(env.workspace)
    for fc in ap.ListFeatureClasses():
        numrec = int(ap.GetCount_management(fc).getOutput(0))
        if numrec > 0:  print ' -FC: {0}: {1} features'.format(fc, numrec)

    print 'Root tables:'
    # Loop through root tables:
    for table in ap.ListTables():
        numrec = int(ap.GetCount_management(table).getOutput(0))
        if numrec > 0:  print ' -Table: {0}: {1} records'.format(table, numrec)

    # Loop through feature datasets:
    for dataset in ap.ListDatasets():
        print 'Feature Dataset: {}'.format(dataset)
        env.workspace = dataset
        for fc in ap.ListFeatureClasses():
            numrec = int(ap.GetCount_management(fc).getOutput(0))
            if numrec > 0:  print ' -FC: {0}: {1} features'.format(fc, numrec)
    print 'This arcpy cataloging took {} sec.'.format(str(time.clock()-tic)[:8])
yorn = raw_input('Copy the lines above and paste into your document/log-file before pressing a key to quit...')