I have several folders which each contain a GDB.
Now, I export the attribute tables of polygon feature classes using the following code (probably could use some optimization):
folder = arcpy.GetParameterAsText(0)
for dirpath, dirnames, filenames in arcpy.da.Walk(folder, datatype="FeatureClass",type="Polygon"):
for filename in filenames:
fc = os.path.join(dirpath, filename)
table = dirpath + os.sep + filename + "_Table"
result = arcpy.GetCount_management(fc)
if int(result.getOutput(0)) > 0:
print "Creating " + table
arcpy.CopyRows_management(fc, table)
Output looks like:
-folder
--subfolder1
---*.gdb <--contains multiple tables
--subfolder2
---*.gdb <--contains multiple tables
I would like to simply output an excel version of the table at the same time, but i am unsure how to parse out the folder containing the .gdb to use as the path for the excel file.
Outout should then look like:
-folder
--subfolder1
---*.gdb <--contains multiple tables
---Excel1
---Excel2
---etc.
--subfolder2
---*.gdb <--contains multiple tables
---Excel1
---Excel2
---etc.
How would I go about getting that parameter to output the Excel file in the correct location?