Hallo,
I have a database that are in file folders and in databases (gdb format). It looks a bit like this
Main File folder
-filefolder “GIS”
-database.gdb B
-featureclass J
-featureclass K
-featureclass L
-database.gdb C
-featureclass J
-featureclass K
-featureclass L
-Filefolder E
-database.gdb F
-featureclass J
-featureclass K
-featureclass L
-database.mgb G
-featureclass J
-featureclass K
-featureclass L
So the names of the folders and the gdb’s are unique but the featuresclass in each gdb have the same name (not the same factor).
What I want is a script that search for all featureclasses J, K and L and rename them. So far I have:
import arcpy
from arcpy import env
import os
# Set the workspace for the ListFeatureClass function
- arcpy.env.workspace = r"D: \GIS\ZONE1\ZONE1_007.gdb"
# Use the ListFeatureClasses function to return a list of all FC.
fclist = arcpy.ListFeatureClasses("*","ALL")
print fclist
# Rename FC
for fc in fclist:
if fc == "TEKST_XX01P_point":
arcpy.Rename_management("TEKST_XX01P_point ", "P_XX01_house")
elif fc == " TEKST_XX032_area ":
arcpy.Rename_management("TEKST_XX032_area", "A_XX032_forest")
print fclist
This works for only gdb set in my workspace. Can anyone help me with the code I need to search also the folders. I was looking at the da.walk function but this is not working for me:
import arcpy
import os
workspace = 😧 \GIS "
feature_classes = []
for dirpath, dirnames, filenames in arcpy.da.Walk(workspace,
datatype="FeatureClass",
type="Polygon"):
for filename in filenames:
feature_classes.append(os.path.join(dirpath, filename))
print filename
thank you greeting peter