import arcgisscripting import sys import fileinput import os import string gp = arcgisscripting.create(9.3) gp.OverWriteOutput = 1 dbfFileA = "c:\\d_drive\\temp\\listFC.dbf" #insert cursor # rows = gp.InsertCursor(dbfFileA) try: for root, dirs, files in os.walk("C:/D_Drive/temp"): for file in files: if file.endswith(".shp"): #print "a" path = os.path.abspath(os.path.join(root, file)) #print path row = rows.NewRow() row.Name = os.path.basename(path) row.Location = path row.Directory = os.path.basename(os.path.dirname(path)) row.Type = "Shapefile" rows.InsertRow(row) elif file.endswith("gdb"): #print "1" path = os.path.abspath(os.path.join(root, file)) #print path row = rows.NewRow() #row.Name = os.path.dirname(path) row.Name = os.path.basename(os.path.dirname(path)) #row.Name = "gdb" row.Location = os.path.dirname(path) row.Directory = os.path.basename(os.path.dirname(path)) row.Type = "File Geodatabase" rows.InsertRow(row) elif file.endswith(".mdb"): #print "3" path = os.path.abspath(os.path.join(root, file)) #print path row = rows.NewRow() row.Name = os.path.basename(path) row.Location = path row.Directory = os.path.basename(os.path.dirname(path)) row.Type = "Personal Geodatabase" rows.InsertRow(row) elif file.endswith("prj.adf"): #print "4" path = os.path.abspath(os.path.join(root, file)) row = rows.NewRow() row.Name = os.path.basename(os.path.dirname(path)) row.Location = os.path.dirname(path) row.Directory = os.path.basename(os.path.dirname(path)) row.Type = "ArcInfo Coverage" rows.InsertRow(row) del rows print "successful" except: print "Error" print gp.getmessages()
for dir in os.listdir(''): if os.path.isdir(dir): # prj.adf seem to occur in every "coverage". if os.path.exists(dir+"/prj.adf"): print " Creating "+dir+".e00 from "+dir+"..." gp.Export_arc("COVER", dir, dir+".e00") gp.GetMessages()
import arcgisscriptingimport sysimport fileinputimport osimport stringgp = arcgisscripting.create(9.3)gp.OverWriteOutput = 1dbfFileA = "c:\\d_drive\\temp\\listFC.dbf"#insert cursor#rows = gp.InsertCursor(dbfFileA) try: for root, dirs, files in os.walk("K:/fish/chpp"): for file in files: if file.endswith(".shp") or file.endswith(".mdb"): path = os.path.abspath(os.path.join(root, file)) #print path row = rows.NewRow() row.Name = os.path.basename(path) row.Location = path rows.InsertRow(row) del rows print "successful"except: print "Error" print gp.getmessages()
Any ideas on how to get a list of arcinfo coverages and personal/file geodatabases as well?Thank you in advance.
# For each ws, print the fc's and tbl's. for ws in arcpy.ListWorkspaces("*", "FileGDB"): arcpy.env.workspace = ws # feature classes for fc in arcpy.ListFeatureClasses(): print fc # tables for tbl in arcpy.ListTables(): print tbl # feature classes in datasets for ds in arcpy.ListDatasets(): arcpy.env.workspace = ds for dfc in arcpy.ListFeatureClasses(): print dfc
Looks like you missed a slash after IA.gdb/arcpy.CopyFeatures_management(path, "K:/COUNTY_MUKEY/IA.gdb/"+base.rstrip(".shp"))
arcpy.CopyFeatures_management(path, "K:/COUNTY_MUKEY/IA.gdb/"+base.rstrip(".shp"))
arcpy.CopyFeatures_management(path, "IA.gdb/"+base.rstrip(".shp"))
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()
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()
# Examples: if file.startswith("rd-") and file.endswith(".dbf"):
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
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
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_)
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_)
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.