Select to view content in your preferred language

trimming character from Output Feature Class in Feature class to feature class conver

535
2
10-11-2012 10:27 AM
LouisEarly
Emerging Contributor
I am trying to use arcpy.FeatureClassToFeatureClass_conversion to move feature classes from one gdb to another. I would like to trim the first 16 characters from the feature class name.

how do i do this? this is how i have it set up with of course the ????? being where i am unsure.

# Set Workspace
env.workspace = r"Database Connections\GENERAL_DATA - PROD.sde"

# List Feature Classes
fcList = arcpy.ListFeatureClasses ("MGISP.GISONEAST*")

# Loop through each feature class
for fc in fcList:


# move features from sde to gis01
arcpy.FeatureClassToFeatureClass_conversion (fc, output_folder + "\\" + my_dir + "\\" + my_gdb, ???????? , "")
Tags (2)
0 Kudos
2 Replies
MathewCoyle
Honored Contributor
Something like this should work.

import arcpy
import os

# Set Workspace
env.workspace = r"Database Connections\GENERAL_DATA - PROD.sde"

# List Feature Classes
fcList = arcpy.ListFeatureClasses("MGISP.GISONEAST*")

# Loop through each feature class
for fc in fcList:

    # move features from sde to gis01
    arcpy.FeatureClassToFeatureClass_conversion(fc, os.path.join(output_folder, my_dir, my_gdb), fc[16:], "")


You could also do something like this, depending on your situation.
fc.lstrip("MGISP.GISONEAST")
0 Kudos
LouisEarly
Emerging Contributor
Thanks, that was it.
0 Kudos