I will write a script that copies only the polygon shapefiles into a file geodatabase called “PPA.gdb”. It will read from the “C:/student/PPA” folder.
I must check for the existence of the PPA geodatabase whenever the script is run. If it exists, it must be deleted, and a new file geodatabase created with the same name. If it does not exist, a new file geodatabase must be created. The script must iterate through the subfolders in the PPA folder, and to iterate through the subfolders, I need to reset and list workspaces (there are two folders under PPA named TT20_3Min, TT20_5Min), and then I need to list polygon by listing feature class.
Here is my code; my code can list the workspace but cannot list the feature class.
import arcpy as ap
# Set the current workspace
ap.env.workspace = "C:/student/PPA/"
# Confirm that the feature class exists
# If exists, it will be deleted, and a new file geodatabase created with the same name.
# If it does not exist, a new file geodatabase will be created.
# Set local variables
out_folder_path = "C:/student/PPA"
out_name = "PPA.gdb"
if ap.Exists("PPA.gdb"):
ap.management.Delete("PPA.gdb")
ap.CreateFileGDB_management("C:/student/PPA/", "PPA.gdb")
else:
ap.CreateFileGDB_management("C:/student/PPA/", "PPA.gdb")
# Listing Workspace
workspaces = ap.ListWorkspaces("*", "Folder")
print(workspaces)
# Listing datasets in workspaces
for i in workspaces:
fc = ap.ListFeatureClasses("*", "Polygon")
print(fc)