Skip to main content
1 of 2

Copying multiple .shp files to a file geodatabase

I am trying to copy multiple shape files to a file geodatabase using python. I have been able to copy single .shp files to a geodatabase. Doing this one at a time is tedious and seems easier to do in ArcMap. I have enclosed the code I am using to do one at a time. How can I make this script work for all .shp files in the folder to be copied to a single geodatabase within that folder?

# Name: CopyFeatures_Example2.py # Description: Convert all shapefiles in a folder to geodatabase feature # classes # Import system modules import arcpy import os # Set environment settings arcpy.env.workspace = "C:/gisdata/roadData" # Set local variables outWorkspace = "C:/GISDATA/RoadData/output.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)