[GIS] ArcGIS Exporting (ALL) layers from Table of Contents

arcgis-10.3arcpyerror-000210

I'm trying to export ALL layers from the table of contents from a map document but I get the following error:

Runtime error Traceback (most recent call last): File "", line 14,
in File "c:\program files
(x86)\arcgis\desktop10.3\arcpy\arcpy\management.py", line 2434, in
CopyFeatures raise e ExecuteError: ERROR 000210: Cannot create output
C:\Users\jnmiller\Desktop\Global_Map.mxd\New_Shapefile.shp Failed to execute
(CopyFeatures).

Python Code:

import os, arcpy

infolder = "‪C:\Users\jnmiller\Desktop\Global_Map.mxd"
outfolder = "C:\EnterpriseFolder\NEO"
#Get name of vector layers in the TOC
mxd = arcpy.mapping.MapDocument("current")
df = arcpy.mapping.ListDataFrames(mxd)[0]
layers = [f.name for f in arcpy.mapping.ListLayers(mxd, "*", df) if         
f.isFeatureLayer]


for layer in layers:
    #Join output infolder to layer name and append .shp
    outfolder = os.path.join(infolder, "{}.shp".format(layer))
    arcpy.CopyFeatures_management(layer, outfolder)

Best Answer

With this:

for layer in layers:
    #Join output infolder to layer name and append .shp
    outfolder = os.path.join(infolder, "{}.shp".format(layer))
    arcpy.CopyFeatures_management(layer, outfolder)

You are trying to copy the features to

C:\Users\jnmiller\Desktop\Global_Map.mxd

Which is not a folder.

I Think this is what you want:

for layer in layers:
    #Join output infolder to layer name and append .shp
    arcpy.CopyFeatures_management(layer, os.path.join(outfolder,"{}.shp".format(layer)))
Related Question