# Import system modules import arcpy from arcpy import env import os # Set environment settings env.workspace = "C:/Users/a391665/Documents/AAAAPERSONALE/rugareto" # Execute CreateFileGDB arcpy.CreateFileGDB_management("C:/park", "test4") # Set local variables outWorkspace = "c:/park/test4.gdb" # Use ListFeatureClasses to generate a list of shapefiles in the # workspace shown above. fcList = arcpy.ListFeatureClasses() # Execute CopyFeatures for each input shapefile for shapefile in fcList: # Determine the new output feature class path and name outFeatureClass = os.path.join(outWorkspace, shapefile.strip(".shp")) arcpy.CopyFeatures_management(shapefile, outFeatureClass)
I do have Percorsi.shp but it doesn't seem to work.
Luca:
Can you add a print statement for each feature class that you loop through in the specified directory? This might be a clue of a problem with the shapefile name.
What does the error say (if any)?
# Import system modules import arcpy from arcpy import env import os # Set environment settings env.workspace = "C:\\Users\\a391665\\Documents\\AAAAPERSONALE\\rugareto\\GIS" print("env.workspace completed successfully") #check GDB exist if os.path.exists("c:\\park\\test4.gdb"): arcpy.Delete_management("c:\\park\\test4.gdb") # Execute CreateFileGDB arcpy.CreateFileGDB_management("C:\\park", "test4") print("CreateFileGDB completed successfully") # Set local variables outWorkspace = "c:\\park\\test4.gdb" print("outWorkspace completed successfully") # Iterate def fcs_in_workspace(workspace): arcpy.env.workspace = workspace for fc in arcpy.ListFeatureClasses(): print os.path.join(workspace, fc) arcpy.FeatureClassToGeodatabase_conversion(fc, outWorkspace) #arcpy.CopyFeatures_management(fc, "c:\\park\\test4.gdb") print os.path.join(workspace, fc, "TO GDB") for ws in arcpy.ListWorkspaces(): fcs_in_workspace(os.path.join(workspace, ws)) fcs_in_workspace("C:\\Users\\a391665\\Documents\\AAAAPERSONALE\\rugareto\\GIS")
Luca:
Can you add the print statement for the feature classes in fcList earlier on in the loop before python hits the error?
Here is where I would put additional print statements for debugging purposes:
# Execute CopyFeatures for each input shapefile
for shapefile in fcList:
# Determine the new output feature class path and name
print("The feature class " + shapefile + " now has the focus")
outFeatureClass = os.path.join(outWorkspace, shapefile.strip(".shp"))
print("The path to the feature class that has the focus is " + outFeatureClass)
arcpy.CopyFeatures_management(shapefile, outFeatureClass)
You might need to change shapefile and outFeatureClass variables to strings if python says they are not in the correct format to be printed out. I think this might provide some additional clues to the problem of python seeing the shapefile that you want copied into the file geodatabase.