AnsweredAssumed Answered

arcpy.da.Walk to not read excel worksheets

Question asked by aimong on Jun 15, 2016
Latest reply on Jun 16, 2016 by bixb0012

My walk code will not skip reading the worksheets inside excel files. Staff have excel files with a huge amount of worksheets that is slowing my walk down so that it is basically unusable. I think it is still reading the excel worksheets in the else statement.

 

import arcpy, os, traceback, sys
arcpy.env.overwriteOutput = True
workspace = r"C:\Users\Documents\GisData"
arcpy.env.workspace = workspace
try:
    walk = arcpy.da.Walk(workspace)
    txt = open(r"C:\Users\Documents\StaffGISLibrary.txt", 'w')
    for dirpath, dirnames, filenames in walk:
        if arcpy.Exists(dirpath):
            #describe = arcpy.Describe(dirpath)
            if dirpath.endswith(('.xls', '.xlsx', '.txt')):
                print "skipping excel file"
                pass
            else:
                for filename in filenames:
                    fullpath = os.path.join(dirpath, filename)
                    describe = arcpy.Describe(fullpath)
                    print "writing " + fullpath
                    txt.write(fullpath + "," + filename + "," + describe.dataType + "\n")
        else:
            print "DOES NOT EXIST"
            pass
    del filename, dirpath, dirnames, filenames
    txt.close() 
except Exception, e:
    pass
    # If an error occurred, print line number and error message
    import traceback, sys
    tb = sys.exc_info()[2]
    print "Line %i" % tb.tb_lineno
    print e.message
finally:
    raw_input("Finished!")

Outcomes