## 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?
Solved! Go to Solution.
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]))
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]))
Please mark questions as questions, not discussions, so credit can be given for providing a correct answer.
Ah ok, didn't get this detail. Will post it again as a question. I think if FC Basson answers again the same he will get the points ...
Double points for double work!
Can you still edit the discussion to mark it as a question? I thought you were allowed to for a certain period of time after creating the discussion, but I may be mistaken.
Can't find the possibility to change a discussion to a question?
I converted it to a question. and will add a couple tags.
Edit:
Johannes Bierer I also marked on of the answers as correct. If that is not the one you wanted, you can unmark, and mark a different one.
Joshua Bixby lol. I'm not moderator on all, but this one I could do.
Great, next time I will just ping you.