#Name: ArcMap Layers to LYR Files with Python
#Author: Bryan McIntosh
#Description: Iterate through an ArcMap MXD, and export all layers to LYR files.
import arcpy, os
#Set the working directory to where the Python file is stored
cwd = os.getcwd()
#Set the location of the MXD file
mxdPath = os.path.join(cwd,"MyMap.mxd")
#Set the location to store LYR files
layersOutPath = os.path.join(cwd,"export")
#Get the MXD and layers
mxd = arcpy.mapping.MapDocument(mxdPath)
layers = arcpy.mapping.ListLayers(mxd)
for layer in layers:
if str(layer.name) == str(layer.longName):
tempOutName = str(layer.name).replace("/","-")
tempOutName = str(tempOutName).replace(":","-")
fn = os.path.join(layersOutPath, str(tempOutName) + ".lyr")
layer.saveACopy(fn)
print "LYR Extraction Complete"