<?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 Re: listing gis files on disc in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/listing-gis-files-on-disc/m-p/580402#M45513</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The workspace variable is the root directory you want it to search for spatial data.&amp;nbsp; So if you set it to "C:/" it would check all folders and subfolders in the C drive for spatial data and write it to a report.&amp;nbsp; If you have a particular folder within a drive say "D:/ForestryData" that has folders and subfolders to be checked and used that as the workspace it would check all folders and subfolders of "D:/ForestryData" for data.&amp;nbsp; I'm not sure if you can point it at a database connection or not.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 03 Jun 2015 21:49:21 GMT</pubDate>
    <dc:creator>IanMurray</dc:creator>
    <dc:date>2015-06-03T21:49:21Z</dc:date>
    <item>
      <title>listing gis files on disc</title>
      <link>https://community.esri.com/t5/python-questions/listing-gis-files-on-disc/m-p/580398#M45509</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have found this script to list shapefiles/geodatabases/dbase files/coverages on a disc.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The script runs well, BUT when i run it a second time, datalines are addded,; so my listing is getting larger every time.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I suppose it is because I use that yield command? Is there a way to avoid this? I am a new user of python/arc python. Can anyoen help me a little bit. I have already read that yield is difficult to understand for new users.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Bart De Bruyn&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;****************************************************************&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import os &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;workspace = r"T:\test" &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;output = r"H:\testlist.txt"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;outFile = open(output, "w")&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;lijn=""&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;def inventory_data(workspace, datatypes):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; """&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Generates full path names under a catalog tree for all requested&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; datatype(s).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Parameters:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; workspace: string&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; The top-level workspace that will be used.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; datatypes: string | list | tuple&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Keyword(s) representing the desired datatypes. A single&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; datatype can be expressed as a string, otherwise use&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a list or tuple. See arcpy.da.Walk documentation&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for a full list.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; """&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for path, path_names, data_names in arcpy.da.Walk(&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; workspace, datatype=datatypes):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for data_name in data_names:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; yield os.path.join(path, data_name)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;for feature_class in inventory_data(r"T:\test", "Any"):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; lijn = lijn + feature_class + "\n"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; outFile.write(lijn)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;outFile.close()&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Mar 2014 15:52:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/listing-gis-files-on-disc/m-p/580398#M45509</guid>
      <dc:creator>BartDe_Bruyn</dc:creator>
      <dc:date>2014-03-12T15:52:43Z</dc:date>
    </item>
    <item>
      <title>Re: listing gis files on disc</title>
      <link>https://community.esri.com/t5/python-questions/listing-gis-files-on-disc/m-p/580399#M45510</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm not sure exactly, but try running this. Is it duplicating your entire list each time?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import os
import arcpy

workspace = r"C:\working\roger"
output = r"C:\testlist.txt"

def inventory_data(workspace, datatypes, output):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """
&amp;nbsp;&amp;nbsp;&amp;nbsp; Generates full path names under a catalog tree for all requested
&amp;nbsp;&amp;nbsp;&amp;nbsp; datatype(s).
&amp;nbsp;&amp;nbsp;&amp;nbsp; Parameters:
&amp;nbsp;&amp;nbsp;&amp;nbsp; workspace: string
&amp;nbsp;&amp;nbsp;&amp;nbsp; The top-level workspace that will be used.
&amp;nbsp;&amp;nbsp;&amp;nbsp; datatypes: string | list | tuple
&amp;nbsp;&amp;nbsp;&amp;nbsp; Keyword(s) representing the desired datatypes. A single
&amp;nbsp;&amp;nbsp;&amp;nbsp; datatype can be expressed as a string, otherwise use
&amp;nbsp;&amp;nbsp;&amp;nbsp; a list or tuple. See arcpy.da.Walk documentation
&amp;nbsp;&amp;nbsp;&amp;nbsp; for a full list.
&amp;nbsp;&amp;nbsp;&amp;nbsp; """
&amp;nbsp;&amp;nbsp;&amp;nbsp; with open(output, "w") as outFile:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for path, path_names, data_names in arcpy.da.Walk(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; workspace, datatype=datatypes):

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for data_name in data_names:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outFile.write(os.path.join(path, data_name) + os.linesep)


inventory_data(workspace, "Any", output)


&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Edit: I think I see the issue, you have too many loops here. Try my revised code above.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Edit2: Silly me the issue is just the lijn variable keeps building up with each loop. Just remove that entirely.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import os
import arcpy

workspace = r"T:\test"
output = r"H:\testlist.txt"


def inventory_data(workspace, datatypes):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """
&amp;nbsp;&amp;nbsp;&amp;nbsp; Generates full path names under a catalog tree for all requested
&amp;nbsp;&amp;nbsp;&amp;nbsp; datatype(s).
&amp;nbsp;&amp;nbsp;&amp;nbsp; Parameters:
&amp;nbsp;&amp;nbsp;&amp;nbsp; workspace: string
&amp;nbsp;&amp;nbsp;&amp;nbsp; The top-level workspace that will be used.
&amp;nbsp;&amp;nbsp;&amp;nbsp; datatypes: string | list | tuple
&amp;nbsp;&amp;nbsp;&amp;nbsp; Keyword(s) representing the desired datatypes. A single
&amp;nbsp;&amp;nbsp;&amp;nbsp; datatype can be expressed as a string, otherwise use
&amp;nbsp;&amp;nbsp;&amp;nbsp; a list or tuple. See arcpy.da.Walk documentation
&amp;nbsp;&amp;nbsp;&amp;nbsp; for a full list.
&amp;nbsp;&amp;nbsp;&amp;nbsp; """
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; for path, path_names, data_names in arcpy.da.Walk(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; workspace, datatype=datatypes):

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for data_name in data_names:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; yield os.path.join(path, data_name)

with open(output, "w") as outFile:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for f in inventory_data(workspace, "Any"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outFile.write(f + os.linesep)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:57:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/listing-gis-files-on-disc/m-p/580399#M45510</guid>
      <dc:creator>MathewCoyle</dc:creator>
      <dc:date>2021-12-12T00:57:43Z</dc:date>
    </item>
    <item>
      <title>Re: listing gis files on disc</title>
      <link>https://community.esri.com/t5/python-questions/listing-gis-files-on-disc/m-p/580400#M45511</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm new to Python. The 'workspace' variable is confusing to me. Do I need a file to be located at that location? Or should that point to my GIS DB server?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jun 2015 21:32:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/listing-gis-files-on-disc/m-p/580400#M45511</guid>
      <dc:creator>BrianO_keefe</dc:creator>
      <dc:date>2015-06-03T21:32:41Z</dc:date>
    </item>
    <item>
      <title>Re: listing gis files on disc</title>
      <link>https://community.esri.com/t5/python-questions/listing-gis-files-on-disc/m-p/580401#M45512</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In this case, I think the &lt;SPAN style="font-family: 'courier new', courier;"&gt;workspace&lt;/SPAN&gt; variable is simply where to start the searching. You could also look into using &lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/018w/018w00000023000000.htm"&gt;arcpy.da.Walk()&lt;/A&gt;&lt;/SPAN&gt;.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jun 2015 21:42:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/listing-gis-files-on-disc/m-p/580401#M45512</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2015-06-03T21:42:27Z</dc:date>
    </item>
    <item>
      <title>Re: listing gis files on disc</title>
      <link>https://community.esri.com/t5/python-questions/listing-gis-files-on-disc/m-p/580402#M45513</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The workspace variable is the root directory you want it to search for spatial data.&amp;nbsp; So if you set it to "C:/" it would check all folders and subfolders in the C drive for spatial data and write it to a report.&amp;nbsp; If you have a particular folder within a drive say "D:/ForestryData" that has folders and subfolders to be checked and used that as the workspace it would check all folders and subfolders of "D:/ForestryData" for data.&amp;nbsp; I'm not sure if you can point it at a database connection or not.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Jun 2015 21:49:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/listing-gis-files-on-disc/m-p/580402#M45513</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2015-06-03T21:49:21Z</dc:date>
    </item>
    <item>
      <title>Re: listing gis files on disc</title>
      <link>https://community.esri.com/t5/python-questions/listing-gis-files-on-disc/m-p/580403#M45514</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I work with Enterprise databases so I have to create SDE connections to datasets within databases. SQL Server. So I don't have a mapped drive letter that will do this. Is there an option for Enterprise level database settings?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Jun 2015 13:39:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/listing-gis-files-on-disc/m-p/580403#M45514</guid>
      <dc:creator>BrianO_keefe</dc:creator>
      <dc:date>2015-06-04T13:39:50Z</dc:date>
    </item>
    <item>
      <title>Re: listing gis files on disc</title>
      <link>https://community.esri.com/t5/python-questions/listing-gis-files-on-disc/m-p/580404#M45515</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It's still just an &lt;A href="http://resources.arcgis.com/en/help/main/10.2/0017/0017000000pt000000.htm"&gt;SDE connection file&lt;/A&gt;. You can either save your connection file to a local (or network) drive, or you can refer to the connection files with a relative path in ArcCatalog as simply "&lt;SPAN style="font-family: 'courier new', courier;"&gt;Database Connections\MyConnectionFile.sde"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;The ArcCatalog connection files are actually stored in a hidden folder at &lt;SPAN style="font-family: 'courier new', courier;"&gt;C:\Users\usernamehere\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I like to have an explicit location where the connection file is. If you had the ArcCatalog relative path, the connections available depend on the particular user logged in to the machine running the script.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Jun 2015 18:37:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/listing-gis-files-on-disc/m-p/580404#M45515</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2015-06-04T18:37:43Z</dc:date>
    </item>
  </channel>
</rss>

