Load data (shp and features) out of multiple folders and subfolders in one FGDB

349
2
Jump to solution
08-08-2016 06:50 AM
JohannesBierer
Regular Contributor
## Load Data

import arcpy
import os

workspace = r"R:\Daten\geo_daten_Kopie"
out_workspace = r"R:\Karto\Bierer2016\OrdnerRDatenGeodatenBereinigen\SIC_Geodaten.gdb\data"

import arcpy
import os

feature_classes = []
for dirpath, dirnames, filenames in arcpy.da.Walk(workspace, datatype="FeatureClass"): ##, type="Polygon"):
    for filename in filenames:
        feature_classes.append(os.path.join(dirpath, filename))
        name = os.path.join(dirpath, filename)
        print name
        BaseName = os.path.basename(name)
        print BaseName
        BaseNameCopy = BaseName.split(".shp")
        print BaseNameCopy
        arcpy.CopyFeatures_management(filename, os.path.join(out_workspace, BaseNameCopy))

The code leads to this error message:

Traceback (most recent call last):

  File "H:/python_scripte/ListFolderandShapes/ListFeatures_FoldersSubfolders_CopyFeatures_3.py", line 22, in <module>

    arcpy.CopyFeatures_management(filename, os.path.join(out_workspace, BaseNameCopy))

  File "C:\Python27\ArcGIS10.2\lib\ntpath.py", line 73, in join

    elif isabs(b):

  File "C:\Python27\ArcGIS10.2\lib\ntpath.py", line 58, in isabs

    return s != '' and s[:1] in '/\\'

TypeError: 'in <string>' requires string as left operand, not list

Anyone has got an idea for a better solution?

0 Kudos
1 Solution

Accepted Solutions
FC_Basson
MVP Regular Contributor

Like I said before, your output basename created after the split creates a list, so you need to access the first item of the list and not the entire list:

BaseNameCopy = BaseName.split(".shp") 
print BaseNameCopy[0] 
arcpy.CopyFeatures_management(filename, os.path.join(out_workspace, BaseNameCopy[0])) 

View solution in original post

2 Replies
FC_Basson
MVP Regular Contributor

Like I said before, your output basename created after the split creates a list, so you need to access the first item of the list and not the entire list:

BaseNameCopy = BaseName.split(".shp") 
print BaseNameCopy[0] 
arcpy.CopyFeatures_management(filename, os.path.join(out_workspace, BaseNameCopy[0])) 
JakeSkinner
Esri Esteemed Contributor

Hi Johannes,

To add onto FC's response, also remove 'data' from your out_workspace so that this is simply referencing a file geodatabase.

out_workspace = r"R:\Karto\Bierer2016\OrdnerRDatenGeodatenBereinigen\SIC_Geodaten.gdb"