<?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 Python List Shapefiles in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/python-list-shapefiles/m-p/199831#M6853</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to list datasets within a directory.&amp;nbsp; I have played with ListDatasets and ListFeatureClasses.&amp;nbsp; These work successfully with geodatabase and CAD layers.&amp;nbsp; How do I construct a Python script that lists shapefiles?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dave.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 21 Apr 2010 05:25:57 GMT</pubDate>
    <dc:creator>DaveMarkey</dc:creator>
    <dc:date>2010-04-21T05:25:57Z</dc:date>
    <item>
      <title>Python List Shapefiles</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-list-shapefiles/m-p/199831#M6853</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to list datasets within a directory.&amp;nbsp; I have played with ListDatasets and ListFeatureClasses.&amp;nbsp; These work successfully with geodatabase and CAD layers.&amp;nbsp; How do I construct a Python script that lists shapefiles?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dave.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Apr 2010 05:25:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-list-shapefiles/m-p/199831#M6853</guid>
      <dc:creator>DaveMarkey</dc:creator>
      <dc:date>2010-04-21T05:25:57Z</dc:date>
    </item>
    <item>
      <title>Python List Shapefiles</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-list-shapefiles/m-p/199832#M6854</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I am trying to list datasets within a directory.&amp;nbsp; I have played with ListDatasets and ListFeatureClasses.&amp;nbsp; These work successfully with geodatabase and CAD layers.&amp;nbsp; How do I construct a Python script that lists shapefiles?&lt;BR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi Dave,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ListFeatureClasses should do the trick.&amp;nbsp; Are you doing something like this below?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy

# Set workspace environment to a folder
arcpy.env.workspace = "c:/temp" 

# A list of shapefiles
arcpy.ListFeatureClasses() &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-Dave&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:57:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-list-shapefiles/m-p/199832#M6854</guid>
      <dc:creator>DavidWynne</dc:creator>
      <dc:date>2021-12-11T09:57:58Z</dc:date>
    </item>
    <item>
      <title>Python List Shapefiles</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-list-shapefiles/m-p/199833#M6855</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I do it like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import os

ws = "c:/temp"

for file in os.listdir(ws):&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; if file.endswith(".shp"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print file&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:58:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-list-shapefiles/m-p/199833#M6855</guid>
      <dc:creator>RDHarles</dc:creator>
      <dc:date>2021-12-11T09:58:01Z</dc:date>
    </item>
    <item>
      <title>Python List Shapefiles</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-list-shapefiles/m-p/199834#M6856</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the responses.&amp;nbsp; Prior to my post I tried the 'listdatasets' and 'listfeatureclasses' but unfortunatlely they do not list shapefiles.&amp;nbsp; This is to be expected from the listfeatureclasses as shapefiles do not exist in a geodatabase file.&amp;nbsp; The listdatasets only lists TIN, Rasters and CAD files, even when the ALL option is specified (please refer to 'List Datasets Methods' in the desktop help).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Fortunately I have found the 'ends with' reply works as desired and appears to be more flexible as could be used for any file type.&amp;nbsp; Could this script be expanded to list multiple file types?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dave.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Apr 2010 22:30:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-list-shapefiles/m-p/199834#M6856</guid>
      <dc:creator>DaveMarkey</dc:creator>
      <dc:date>2010-04-21T22:30:18Z</dc:date>
    </item>
    <item>
      <title>Python List Shapefiles</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-list-shapefiles/m-p/199835#M6857</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;There was a bug with the ListFeatureClasses method (introduced by a particular service pack) in 9.2&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;See here this thread in the old forums &lt;/SPAN&gt;&lt;A href="http://forums.esri.com/Thread.asp?c=93&amp;amp;f=1729&amp;amp;t=240535"&gt;http://forums.esri.com/Thread.asp?c=93&amp;amp;f=1729&amp;amp;t=240535&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Apr 2010 06:49:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-list-shapefiles/m-p/199835#M6857</guid>
      <dc:creator>DarshaHardy</dc:creator>
      <dc:date>2010-04-22T06:49:25Z</dc:date>
    </item>
    <item>
      <title>Python List Shapefiles</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-list-shapefiles/m-p/199836#M6858</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&amp;nbsp; Could this script be expanded to list multiple file types?.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sure.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;List all files that end with .shp &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;&lt;STRONG&gt;or&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN&gt; .dxf &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;&lt;STRONG&gt;or&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN&gt; start with 'str':&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import os

ws = "c:/temp"

for file in os.listdir(ws):&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; if file.endswith(".shp") or file.endswith(".dxf") or file.startswith("str"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print file&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can also use wildcards like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import os, glob
# Delete all files that contain the word 'points'
for file in glob.glob("*points*"):
&amp;nbsp;&amp;nbsp;&amp;nbsp; os.remove(file)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:58:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-list-shapefiles/m-p/199836#M6858</guid>
      <dc:creator>RDHarles</dc:creator>
      <dc:date>2021-12-11T09:58:04Z</dc:date>
    </item>
    <item>
      <title>Python List Shapefiles</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/python-list-shapefiles/m-p/199837#M6859</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks people.&amp;nbsp; Some good ideas here.&amp;nbsp; I am wanting to learn Python from an ArcGIS perspective.&amp;nbsp; Where is some good learning material that teaches Python for ArcGIS?&amp;nbsp; I have downloaded the documentation from Python website but is only good for learning from scratch.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, thanks for the heads up on the ListFeatureClasses bug.&amp;nbsp; Appears this should work with shapefiles but doesn't due to a service pack.&amp;nbsp; For those of us managing and developing ArcPad, this could be a real problem as ArcPad mostly only works with shapefiles.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dave.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Apr 2010 21:49:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/python-list-shapefiles/m-p/199837#M6859</guid>
      <dc:creator>DaveMarkey</dc:creator>
      <dc:date>2010-04-22T21:49:40Z</dc:date>
    </item>
  </channel>
</rss>

