shape_list = ["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"] arcpy.FeatureClassToGeodatabase_conversion(shape_list, IA_gdb__2_)
Is there some kind of processing you need to do that requires you to loop through a list? You can simply create a list of shapefiles and bulk load them as you have done.
You could try just making it a list to be more readableshape_list = ["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"] arcpy.FeatureClassToGeodatabase_conversion(shape_list, IA_gdb__2_)
import os for root, dirs, files in os.walk("c:/shapefiles"): for file in files: if file.endswith(".shp"): path = os.path.abspath(os.path.join(root, file)) print path
This will find EVERY shapefile in EVERY directory in the path you choose to start from (c:/shapefiles in the example below).
Then you can do whatever you want with the shapefile.import os for root, dirs, files in os.walk("c:/shapefiles"): for file in files: if file.endswith(".shp"): path = os.path.abspath(os.path.join(root, file)) print path
# Examples: if file.startswith("rd-") and file.endswith(".dbf"):
import arcpy, os # Set the workspace arcpy.env.workspace= "K:/SUURGO_Data/IA" # To create list files from directories and subdirectories for root, dirs, files in os.walk(arcpy.env.workspace): for name in files: if name.startswith("soilmu_a_") and name.endswith(".shp"): path = os.path.abspath(os.path.join(root, name)) # Remove the path from the shapefile name base = os.path.basename(path) print "Processing "+base # CopyFeatures arcpy.CopyFeatures_management(base, "IA.gdb/"+base.rstrip(".shp")) print arcpy.GetMessages()
I changed quite a bit of the code, this should work now.import arcpy, os # Set the workspace arcpy.env.workspace= "K:/SUURGO_Data/IA" # To create list files from directories and subdirectories for root, dirs, files in os.walk(arcpy.env.workspace): for name in files: if name.startswith("soilmu_a_") and name.endswith(".shp"): path = os.path.abspath(os.path.join(root, name)) # Remove the path from the shapefile name base = os.path.basename(path) print "Processing "+base # CopyFeatures arcpy.CopyFeatures_management(base, "IA.gdb/"+base.rstrip(".shp")) print arcpy.GetMessages()
arcpy.CopyFeatures_management(path, "IA.gdb/"+base.rstrip(".shp"))