<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Script to print all data layer names and sources? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/script-to-print-all-data-layer-names-and-sources/m-p/203713#M15644</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello! In a couple of Esri's python tutorials, they reference the capability of generating a printed document which lists all the data layers in an individual mxd, along with the source of those layers. I would like to do this, but can't find any sample script for it online. Thoughts? Thank you!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 13 Jun 2011 21:14:38 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2011-06-13T21:14:38Z</dc:date>
    <item>
      <title>Script to print all data layer names and sources?</title>
      <link>https://community.esri.com/t5/python-questions/script-to-print-all-data-layer-names-and-sources/m-p/203713#M15644</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello! In a couple of Esri's python tutorials, they reference the capability of generating a printed document which lists all the data layers in an individual mxd, along with the source of those layers. I would like to do this, but can't find any sample script for it online. Thoughts? Thank you!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 13 Jun 2011 21:14:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-print-all-data-layer-names-and-sources/m-p/203713#M15644</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2011-06-13T21:14:38Z</dc:date>
    </item>
    <item>
      <title>Re: Script to print all data layer names and sources?</title>
      <link>https://community.esri.com/t5/python-questions/script-to-print-all-data-layer-names-and-sources/m-p/203714#M15645</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm not sure about printing (can't test here), but this will list the data source of each layer (&lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Layer/00s300000008000000/" rel="nofollow noopener noreferrer" target="_blank"&gt;help here&lt;/A&gt;&lt;SPAN&gt;) in a mxd (you can just as easily print the layer name):&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy

mxd = arcpy.mapping.MapDocument("MXD PATH HERE")
layers = arcpy.mapping.ListLayers(mxd)

for layer in layers:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if layer.supports("dataSource"): # some layers might not support the property "dataSource"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print layer.dataSource&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:06:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-print-all-data-layer-names-and-sources/m-p/203714#M15645</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-11T10:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: Script to print all data layer names and sources?</title>
      <link>https://community.esri.com/t5/python-questions/script-to-print-all-data-layer-names-and-sources/m-p/203715#M15646</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Using Darren's code above, simply write each layer.dataSource to a text file for printing like so:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy

doc = open("doc.txt", "a")

mxd = arcpy.mapping.MapDocument("MXD PATH HERE")
layers = arcpy.mapping.ListLayers(mxd)

for layer in layers:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if layer.supports("dataSource"): # some layers might not support the property "dataSource"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print layer.dataSource
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; doc.write(layer.dataSource+"\n")
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:06:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-print-all-data-layer-names-and-sources/m-p/203715#M15646</guid>
      <dc:creator>RDHarles</dc:creator>
      <dc:date>2021-12-11T10:06:48Z</dc:date>
    </item>
    <item>
      <title>Re: Script to print all data layer names and sources?</title>
      <link>https://community.esri.com/t5/python-questions/script-to-print-all-data-layer-names-and-sources/m-p/203716#M15647</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you; this is perfect!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Jun 2011 14:17:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-print-all-data-layer-names-and-sources/m-p/203716#M15647</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2011-06-14T14:17:56Z</dc:date>
    </item>
    <item>
      <title>Re: Script to print all data layer names and sources?</title>
      <link>https://community.esri.com/t5/python-questions/script-to-print-all-data-layer-names-and-sources/m-p/203717#M15648</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Using Darren's code above, simply write each layer.dataSource to a text file for printing like so:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy

doc = open("doc.txt", "a")

mxd = arcpy.mapping.MapDocument("MXD PATH HERE")
layers = arcpy.mapping.ListLayers(mxd)

for layer in layers:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if layer.supports("dataSource"): # some layers might not support the property "dataSource"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print layer.dataSource
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; doc.write(layer.dataSource+"\n")
&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Is it possible for the script to:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;a) write this output in a delimited format (the txt is undelimitable, if that's a word, due to the many backslashes in all the path names)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;b) create the txt, instead of pouring into an existing txt file&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:06:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-print-all-data-layer-names-and-sources/m-p/203717#M15648</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-11T10:06:51Z</dc:date>
    </item>
    <item>
      <title>Re: Script to print all data layer names and sources?</title>
      <link>https://community.esri.com/t5/python-questions/script-to-print-all-data-layer-names-and-sources/m-p/203718#M15649</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This code will create and write to a new csv file. Unfortunately, it delimits every character, and I haven't figured out how to fix that. If you do, please post how.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, csv

mxd = arcpy.mapping.MapDocument("YOUR MXD HERE")
layers = arcpy.mapping.ListLayers(mxd)
filepath = "NEW CSV FILE PATH HERE"
writer = csv.writer(file(filepath, 'w'))

for layer in layers:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if layer.supports("dataSource"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; writer.writerow(layer.dataSource)
del writer&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EDIT: this works&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy, csv

mxd = arcpy.mapping.MapDocument("YOUR MXD HERE")
layers = arcpy.mapping.ListLayers(mxd)
filepath = "NEW CSV FILE PATH HERE"
writer = csv.writer(file(filepath, 'wb'))
sourcelist = []

for layer in layers:
&amp;nbsp;&amp;nbsp;&amp;nbsp; if layer.supports("dataSource"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sourcelist.append(layer.dataSource)
writer.writerow(sourcelist)
del writer&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:06:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-print-all-data-layer-names-and-sources/m-p/203718#M15649</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-11T10:06:53Z</dc:date>
    </item>
    <item>
      <title>Re: Script to print all data layer names and sources?</title>
      <link>https://community.esri.com/t5/python-questions/script-to-print-all-data-layer-names-and-sources/m-p/203719#M15650</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello! I keep getting this error with the second script: Runtime error &amp;lt;type 'exceptions.IOError'&amp;gt;: [Errno 22] invalid mode ('wb') or filename: ' F:\\MLF\\Special Projects\\District_Maps'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What am I doing wrong?&amp;nbsp; Thank you!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To clarify: this is the code I entered:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy, csv&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mxd = arcpy.mapping.MapDocument("CURRENT")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;layers = arcpy.mapping.ListLayers(mxd)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;filepath = " F:\MLF\Special Projects\District_Maps"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;writer = csv.writer(file(filepath, 'wb'))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sourcelist = []&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for layer in layers:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if layer.supports("dataSource"):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sourcelist.append(layer.dataSource)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;writer.writerow(sourcelist)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;del writer&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2011 13:31:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-print-all-data-layer-names-and-sources/m-p/203719#M15650</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2011-06-16T13:31:39Z</dc:date>
    </item>
    <item>
      <title>Re: Script to print all data layer names and sources?</title>
      <link>https://community.esri.com/t5/python-questions/script-to-print-all-data-layer-names-and-sources/m-p/203720#M15651</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try taking out the space before your filename. Other than that, I think the 'wb' option might depend on your version of python, and possibly operating system. I'm using 2.6.5 on Windows 2008, but actually I was going off examples from 2.7. I see posts from 2.6 users who say to use 'w', so maybe try that.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jun 2011 14:42:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-print-all-data-layer-names-and-sources/m-p/203720#M15651</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2011-06-16T14:42:06Z</dc:date>
    </item>
    <item>
      <title>Re: Script to print all data layer names and sources?</title>
      <link>https://community.esri.com/t5/python-questions/script-to-print-all-data-layer-names-and-sources/m-p/203721#M15652</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am looking for a way to list all .mxd files in a directory "P:\data\" that have certain .shp file data layer in them.&amp;nbsp; I have about 1400 .mxd files in my "P:\data\many subfolders\many subfolders".&amp;nbsp; I would like to find which of the 1400 .mxd files have a special.shp file data layer in the .mxd file.&amp;nbsp; I need to know which .mxd files have the special.shp data layer in the whole directory.&amp;nbsp; Can this be done and can someone please help me.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Dec 2013 15:16:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-print-all-data-layer-names-and-sources/m-p/203721#M15652</guid>
      <dc:creator>EricPotvin</dc:creator>
      <dc:date>2013-12-02T15:16:54Z</dc:date>
    </item>
    <item>
      <title>Re: Script to print all data layer names and sources?</title>
      <link>https://community.esri.com/t5/python-questions/script-to-print-all-data-layer-names-and-sources/m-p/203722#M15653</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Have you seen these samples:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.arcgis.com/home/item.html?id=18c19ec00acb4d568c27bc20a72bfdc8"&gt;http://www.arcgis.com/home/item.html?id=18c19ec00acb4d568c27bc20a72bfdc8&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There are about 20 sample scripts.&amp;nbsp; One is called "Find Data Source" and I believe it does exactly what you want.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Dec 2013 14:33:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-print-all-data-layer-names-and-sources/m-p/203722#M15653</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2013-12-03T14:33:51Z</dc:date>
    </item>
    <item>
      <title>Re: Script to print all data layer names and sources?</title>
      <link>https://community.esri.com/t5/python-questions/script-to-print-all-data-layer-names-and-sources/m-p/203723#M15654</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Darren! This worked on my first try for me. WOOO!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Apr 2018 14:10:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/script-to-print-all-data-layer-names-and-sources/m-p/203723#M15654</guid>
      <dc:creator>pokateo_</dc:creator>
      <dc:date>2018-04-05T14:10:05Z</dc:date>
    </item>
  </channel>
</rss>

