I am trying to create a Python script that batch projects every shapefile in a geodatabase to a temporary geodatabase that I created. I realized that this script that I created does not iterate through the multiple feature datasets of the geodatabase.

enter image description here

The code that I created only projects the file "breaklines". I need to also iterate through "Contours" and "Hydro". I know that I need to create a double loop but I am not sure how to do it. Here is the code that I started below

import glob, os, shutil, time, arcpy

path = r"C:\...\SARA_New_Contours.gdb"
temp = r"C:\...\Temp.gdb"

string1 = "\\metersproj-"

arcpy.env.workspace = path
out_coor_system = arcpy.SpatialReference("C:\...\NAD 1983 (2011) StatePlane Texas S Central FIPS 4204 (Meters).prj")

for fc in arcpy.ListFeatureClasses():
    prefix = string1 + fc
    out_dataset = temp + "\\" + prefix
    arcpy.Project_management (fc, out_dataset, out_coor_system)

A side question: How would I just loop through one dataset, for example: just the feature dataset called "Contours"?

closed as too broad by PolyGeo Mar 11 at 20:07

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Those aren't "folders" -- they're Feature Datasets, which are displayed in the UI as folders. Look at the ListDatasets documentation. – Vince Mar 11 at 14:51
  • Thank you! I updated the question to make more sense. Still having trouble figuring it out. I know its an easy fix, taking a long to time to read and figure it out. What is the one line of code that I am missing? – Apmartin Mar 11 at 14:58
  • 1
    As per the Tour there should be only one question asked per question. – PolyGeo Mar 11 at 20:08

You can treat the feature dataset as a sub-folder of the file geodatabase. Set path = r"C:\...\SARA_New_Contours.gdb\Contours", and your arcpy.ListFeatureClasses() will only return the contents of Contours.


Just to add to Bjorn's answer.

You can iterate through all the feature datasets within a file geodatabase (or SDE) with the following:

fcList = []
for fds in arcpy.ListDatasets('', 'feature'):
    for fc in arcpy.ListFeatureClasses('','',fds):

This will attach all the feature classes to a list which you can then work with.

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