zia207

Help: looping funtion to creat a list for the files from different folders

Discussion created by zia207 on Aug 11, 2011
Latest reply on Apr 26, 2012 by toddmcd
I am very new in Python.  I am trying to import several featue classess into file geodatabse (name: IA.gdb)  using a script. These files are in located in diffrent folders. For example: 
K:\SUURGO_Data\IA\soil_ia001\soil_ia001\spatial\soilmu_a_ia001.shp
K:\SUURGO_Data\IA\soil_ia001\soil_ia003\spatial\soilmu_a_ia003.shp
K:\SUURGO_Data\IA\soil_ia001\soil_ia005\spatial\soilmu_a_ia005.shp
K:\SUURGO_Data\IA\soil_ia001\soil_ia053\spatial\soilmu_a_ia053.shp
K:\SUURGO_Data\IA\soil_ia001\soil_ia193\spatial\soilmu_a_ia193.shp
.... so on

I used model bulider to do this for a  few number of files. But I want to do this with a loop to select (list)  all of these files  and import to a filegeodata base. I do not know how to write a loop function get the list of files located in different folders and subfolders.   Help will be highly appreciated.  Below find a python script - saved from Model Bulder.

Thanks
Zia

--------------------------------------------------------------------------
# ImprtFetureGeodatabse.py
# Created on: 2011-08-11 17:44:46.00000
#   (generated by ArcGIS/ModelBuilder)
# Description:
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy


# Local variables:
soilmu_a_ia001_shp = "K:\\SUURGO_Data\\IA\\soil_ia001\\soil_ia001\\spatial\\soilmu_a_ia001.shp"
soilmu_a_ia003_shp = "K:\\SUURGO_Data\\IA\\soil_ia003\\soil_ia003\\spatial\\soilmu_a_ia003.shp"
soilmu_a_ia005_shp = "K:\\SUURGO_Data\\IA\\soil_ia005\\soil_ia005\\spatial\\soilmu_a_ia005.shp"
soilmu_a_ia197_shp = "K:\\SUURGO_Data\\IA\\soil_ia197\\soil_ia197\\spatial\\soilmu_a_ia197.shp"
soilmu_a_ia053_shp = "K:\\SUURGO_Data\\IA\\soil_ia053\\soil_ia053\\spatial\\soilmu_a_ia053.shp"
IA_gdb__2_ = "K:\\COUNTY_MUKEY\\IA.gdb"

# Process: Feature Class to Geodatabase (multiple)
arcpy.FeatureClassToGeodatabase_conversion("K:\\SUURGO_Data\\IA\\soil_ia001\\soil_ia001\\spatial\\soilmu_a_ia001.shp;K:\\SUURGO_Data\\IA\\soil_ia003\\soil_ia003\\spatial\\soilmu_a_ia003.shp;K:\\SUURGO_Data\\IA\\soil_ia005\\soil_ia005\\spatial\\soilmu_a_ia005.shp;K:\\SUURGO_Data\\IA\\soil_ia197\\soil_ia197\\spatial\\soilmu_a_ia197.shp;K:\\SUURGO_Data\\IA\\soil_ia053\\soil_ia053\\spatial\\soilmu_a_ia053.shp", IA_gdb__2_)
###############################################################

Outcomes