Batch Copy Shapefiles to Geodatabse: How to improve current script

Discussion created by Playa on May 20, 2012
Latest reply on May 20, 2012 by bruce.nielsen
Firstly, please note that I'm new to programming and Python. I've created the following Python script to loop through a directory, validate the shapefile names that I then copy to a specified File Geodatabase. The are some shapefiles that have that already have "_shp" attached the shapefile name and the "ValidateTableName" adds "_shp" to the output Feature Class. I have striped out "_shp" before copy the shapefile to the Geodatabase. I have noticed that where the shapefile already had "_shp" it drops an additional character at the end. How to i prevent this from happenning. i.e. citiespop_shp.shp = citispo

import arcpy, os
... arcpy.env.workspace = r"S:\Projects\H108392\H108392.gdb"
... arcpy.env.OverwriteOutput = True
... inWksp = r"S:\Projects\H108392\data_received\KageraMonograph\KAGERA_GIS\_Vector_Data"
... for root, dirs, files in os.walk(inWksp):
...     for name in files:
...         if name.endswith(".shp"):
...             path = os.path.abspath(os.path.join(root, name))
...             base = arcpy.ValidateTableName(os.path.basename(path))
...             print "Processing "+base
...             arcpy.CopyFeatures_management(path, "S:/Projects/H108392/H108392.gdb/"+base.rstrip("_shp"))

Any advice would be appreciated and as well as any pointers wher I could improve the structure of my code.