This is a continuation of the question I asked here:
At this point I'm really just trying to get everything in one place and keep the original shapefile basename. I'll tackle merging like-named files later, which is why I'm using CopyFeatures for now. I'm confused about why the second sample below didn't have a result list similar to the first one. It looks like the first sample ran through the first folder and copied those shapefiles to the gdb, and when it got to the next folder with a 'Bank_Ero' name it failed.
So now, I'd like to create a unique file name (keeping that original shp base name) if one already exists. As always, any hints, or direction will be greatly appreciated, and thanks for looking.
Original sample:
for dirname, dirnames, filenames in os.walk ("C:\FOR MIKEK\GPS Files\GPS_ANDY"): for subdirname in dirnames: env.workspace = os.path.join(dirname, subdirname) All_List = arcpy.ListFeatureClasses() for shp in All_List: outFeatureClass = os.path.join("C:\FOR MIKEK\Python_Scratch.gdb", shp.strip(".shp")) arcpy.CopyFeatures_management(shp, outFeatureClass)Traceback (most recent call last): File "", line 7, in arcpy.CopyFeatures_management(shp, outFeatureClass) File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\management.py", line 1943, in CopyFeatures raise eExecuteError: Failed to execute. Parameters are not valid.ERROR 000725: Output Feature Class: Dataset C:\FOR MIKEK\Python_Scratch.gdb\Bank_Ero already exists.Failed to execute (CopyFeatures).and now attempting to use CreateUniqueName:
import arcpy, os>>> from arcpy import env>>> env.workspace = "C:\FOR MIKEK\GPS Files\GPS_ANDY">>> for dirname, dirnames, filesnames in os.walk ("C:\FOR MIKEK\GPS Files\GPS_ANDY"): for subdirname in dirnames: env.workspace = os.path.join(dirname, subdirname) shpList = arcpy.ListFeatureClasses() for shp in shpList: outFC = os.path.join("C:\FOR MIKEK\Python_Scratch.gdb", shp.strip (".shp")) if arcpy.Exists(outFC): arcpy.CreateUniqueName(os.path.join, "C:\FOR MIKEK\Python_Scratch.gdb") arcpy.CopyFeatures_management(shp, outFC)>>> xferFiles = arcpy.ListFeatureClasses("C:\FOR MIKEK\Python_Scratch.gdb")>>> print xferFiles[]
أكثر...
At this point I'm really just trying to get everything in one place and keep the original shapefile basename. I'll tackle merging like-named files later, which is why I'm using CopyFeatures for now. I'm confused about why the second sample below didn't have a result list similar to the first one. It looks like the first sample ran through the first folder and copied those shapefiles to the gdb, and when it got to the next folder with a 'Bank_Ero' name it failed.
So now, I'd like to create a unique file name (keeping that original shp base name) if one already exists. As always, any hints, or direction will be greatly appreciated, and thanks for looking.
Original sample:
for dirname, dirnames, filenames in os.walk ("C:\FOR MIKEK\GPS Files\GPS_ANDY"): for subdirname in dirnames: env.workspace = os.path.join(dirname, subdirname) All_List = arcpy.ListFeatureClasses() for shp in All_List: outFeatureClass = os.path.join("C:\FOR MIKEK\Python_Scratch.gdb", shp.strip(".shp")) arcpy.CopyFeatures_management(shp, outFeatureClass)Traceback (most recent call last): File "", line 7, in arcpy.CopyFeatures_management(shp, outFeatureClass) File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\management.py", line 1943, in CopyFeatures raise eExecuteError: Failed to execute. Parameters are not valid.ERROR 000725: Output Feature Class: Dataset C:\FOR MIKEK\Python_Scratch.gdb\Bank_Ero already exists.Failed to execute (CopyFeatures).and now attempting to use CreateUniqueName:
import arcpy, os>>> from arcpy import env>>> env.workspace = "C:\FOR MIKEK\GPS Files\GPS_ANDY">>> for dirname, dirnames, filesnames in os.walk ("C:\FOR MIKEK\GPS Files\GPS_ANDY"): for subdirname in dirnames: env.workspace = os.path.join(dirname, subdirname) shpList = arcpy.ListFeatureClasses() for shp in shpList: outFC = os.path.join("C:\FOR MIKEK\Python_Scratch.gdb", shp.strip (".shp")) if arcpy.Exists(outFC): arcpy.CreateUniqueName(os.path.join, "C:\FOR MIKEK\Python_Scratch.gdb") arcpy.CopyFeatures_management(shp, outFC)>>> xferFiles = arcpy.ListFeatureClasses("C:\FOR MIKEK\Python_Scratch.gdb")>>> print xferFiles[]
أكثر...