2

I'm fairly new to the arcpy world. I am trying to create a script in 10.0 that will load a dataset (file geodatabase) into ArcSDE and rename the feature classes with a prefix, i.e. San_Diego_Bay -> AJ_San_Diego_Bay. My script is below and is very basic for loading shapefiles into a geodatabase. I would like to load a file geodatabase into an ArcSDE Feature Dataset. Any help would be greatly appreciated.

import arcpy
from arcpy import env

# Set environment settings
env.workspace = "Z:/Data/Test_arcpy"

# Set local variables
inFeatures = ["Atlantic_Offshore_Areas.shp", "C_C_mauritania.shp", "E_Class.shp", "San_Diego_Bay.shp"]
outLocation = "Z:/Data/Test_arcpy/test_two_arcpy.gdb"

# Execute TableToGeodatabase
arcpy.FeatureClassToGeodatabase_conversion(inFeatures, outLocation)

1 Answer 1

3

The attached script should help. The general idea here is to loop through your directory with a for loop and use Feature Class to Feature class to copy the shapefiles to a FGDB. When you define the output name, you have to strip the ".shp" extension or else you will receive errors.

# Import system modules
import arcpy
from arcpy import env

# Set workspace
env.workspace = "Z:/Data/Test_arcpy"
Dir = env.workspace

# Set local variables
out_path = "Z:/Data/Test_arcpy/test_two_arcpy.gdb"

# List the shapefiles in your directory
fclist = arcpy.ListFeatureClasses()

# Alternatively, create your own subset
#fclist = ["Atlantic_Offshore_Areas.shp", "C_C_mauritania.shp", "E_Class.shp", "San_Diego_Bay.shp"]

for fc in fclist:

    # Manipulate the string
    name = "AJ_" + str(fc.rsplit(".",1)[0])

     # Execute FeatureClassToFeatureClass
    arcpy.FeatureClassToFeatureClass_conversion(fc, out_path, name)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.