0

I have geodatabase with many feature classes. Filenames of these fc have all info I need. My goal is to have a CSV or Excel table, that I can work with.

So all filenames match schema What_Where_HowMany.

eg.

C:\GIS\Data.gdb\Egs_Basket_10
C:\GIS\Data.gdb\Milk_Fridge_2

What I want to get:

Egs Basket 10
Milk Fridge 2
...

I'm interested in other solutions too.

1
  • 2
    What have you tried? Replacing underscores with space is a trivial capability of Python, as is stripping a full file path to just the base name, and ArcPy can list feature classes.
    – Vince
    Jan 30, 2020 at 13:57

1 Answer 1

1

The following is how I would solve such a problem. The method is not tested.

import arcpy 

# define workspace
workspace = r"C:\GIS\Data.gdb"
arcpy.env.workspace = workspace

# list all feature classes
fullList = arcpy.ListFeatureClasses()

# set up empty list
resultList = []

# iterate through files in list and fill new list
for item in fullList:
    resultList.append(item.split("_"))

# your new list now contains lists in the form of ["what", "where", "howMany"]
# you can use this list to fill a text file with its content
# define output file
outfile = r"C:\GIS\output.txt"
# fill output file
with open(outfile, 'w') as fout:
    # write header:
    fout.write("what where howMany\n")
    # write list content
    for i in range(len(resultList)):
        fout.write("{} {} {}\n".format(str(resultList[i][0]), str(resultList[i][1]), int(resultList[i][2])))
1
  • Thank you! this was it!
    – mik
    Jan 31, 2020 at 7:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.