Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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)
share|improve this question

1 Answer 1

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)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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