<?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: Print files in folder as ArcCatalog sees them in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/print-files-in-folder-as-arccatalog-sees-them/m-p/1248189#M66547</link>
    <description>&lt;P&gt;I think the issue may be that you're modifying TList while trying to iterate over it.&amp;nbsp; If you print(f) in every iteration, you'll see that not all of the original items are printed. You should create a new list and append to instead of modifying the existing list.&lt;/P&gt;</description>
    <pubDate>Fri, 13 Jan 2023 19:28:24 GMT</pubDate>
    <dc:creator>JeffreyHolycross</dc:creator>
    <dc:date>2023-01-13T19:28:24Z</dc:date>
    <item>
      <title>Print files in folder as ArcCatalog sees them</title>
      <link>https://community.esri.com/t5/python-questions/print-files-in-folder-as-arccatalog-sees-them/m-p/1247853#M66527</link>
      <description>&lt;P&gt;Forgive me if I've asked this before.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Does anyone have a script written to return all the files in folder as Catalog sees them?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I can use arcpy.ListFiles(), but I don't want to see all the components that make up a shapefile, I just want to see the shapefile.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Similarly, I could use arcpy.ListFeatureClasses() or ...Tables, etc., but that would ignore non-GIS files.&lt;/P&gt;&lt;P&gt;&lt;U&gt;For example, how could I cleanly return the contents of this folder, more or less as I see it here?&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AlfredBaldenweck_0-1673560121727.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/60328iC79248F9ECB157A9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AlfredBaldenweck_0-1673560121727.png" alt="AlfredBaldenweck_0-1673560121727.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Compare to file explorer:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AlfredBaldenweck_1-1673560252897.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/60329i80C069652B9813BE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AlfredBaldenweck_1-1673560252897.png" alt="AlfredBaldenweck_1-1673560252897.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2023 21:51:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/print-files-in-folder-as-arccatalog-sees-them/m-p/1247853#M66527</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2023-01-12T21:51:59Z</dc:date>
    </item>
    <item>
      <title>Re: Print files in folder as ArcCatalog sees them</title>
      <link>https://community.esri.com/t5/python-questions/print-files-in-folder-as-arccatalog-sees-them/m-p/1247892#M66528</link>
      <description>&lt;P&gt;You can try something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from os import path
def getFiles():
    def fname(x): return path.splitext(path.basename(x))[0]
    gisFiles = arcpy.ListFeatureClasses() + arcpy.ListTables() + arcpy.ListRasters()  # And so on so forth.
    gisBaseNames = {fname(g) for g in gisFiles}
    otherFiles = [f for f in arcpy.ListFiles() if fname(f) not in gisBaseNames]
    return sorted(gisFiles + otherFiles)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The catch is if you have, say, "mydata.shp" and "mydata.xlsx" in the same folder you'll lose the xlsx file. The fix for that is to build up a list of known special GIS extensions and split those files out, but that's a bit harder to write up so this should be a starting point at least.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2023 23:17:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/print-files-in-folder-as-arccatalog-sees-them/m-p/1247892#M66528</guid>
      <dc:creator>DavidSolari</dc:creator>
      <dc:date>2023-01-12T23:17:33Z</dc:date>
    </item>
    <item>
      <title>Re: Print files in folder as ArcCatalog sees them</title>
      <link>https://community.esri.com/t5/python-questions/print-files-in-folder-as-arccatalog-sees-them/m-p/1248038#M66533</link>
      <description>&lt;P&gt;Just add the types you want to see to the files list. This will get files that are named the same but with different extensions as well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;files = ['.shp', '.txt', '.xlsx', '.csv', ...]
filteredFiles = [f for f in os.listdir(r'your path') if os.path.splitext(f)[1] in files]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you wanted gdb's, you can use the&amp;nbsp; for root, dir, files in os.walk(): method and filter the dir if it contains .gdb in the name.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2023 14:09:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/print-files-in-folder-as-arccatalog-sees-them/m-p/1248038#M66533</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2023-01-13T14:09:01Z</dc:date>
    </item>
    <item>
      <title>Re: Print files in folder as ArcCatalog sees them</title>
      <link>https://community.esri.com/t5/python-questions/print-files-in-folder-as-arccatalog-sees-them/m-p/1248179#M66544</link>
      <description>&lt;P&gt;I'm going for a variation on this method, but I'm running into a weird issue. It's ignoring some of the shapefile parts when I'm telling it to remove them.&lt;/P&gt;&lt;P&gt;See here:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;for r in rootL:
    arcpy.env.workspace = r
    ignoreExt = ['.shp', '.shx', '.dbf', '.prj', '.xml', '.sbn', '.sbx', '.cpg', '.aux']

    TList= ['test.shp', 'test.shx', 'test.dbf', 'test.prj', 'test.xml', 'test.sbn', 'test.sbx', 'test.cpg', 'test.aux' ]
    
    for f in TList:
        #print(os.path.splitext(f)[1])
        if os.path.splitext(f)[1] in ignoreExt:
            #print(f)
            TList.remove(f)
            
    print(TList)
    # ['test.shx', 'test.prj', 'test.sbn', 'test.cpg']&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Why are these files still in the list?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit: Apparently splitext() is ignoring those files. What's weirder is that it doesn't ignore it if you feed them to it directly; os.path.splitext('test.shx')[1] will correctly yield ".shx"&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2023 19:22:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/print-files-in-folder-as-arccatalog-sees-them/m-p/1248179#M66544</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2023-01-13T19:22:18Z</dc:date>
    </item>
    <item>
      <title>Re: Print files in folder as ArcCatalog sees them</title>
      <link>https://community.esri.com/t5/python-questions/print-files-in-folder-as-arccatalog-sees-them/m-p/1248187#M66546</link>
      <description>&lt;P&gt;You shouldn't remove items from an Array that you are iterating over, unless you are going in reverse.&amp;nbsp; It is skipping those .shx, .prj, .sbn, .cpg extensions because the statement for f in TList just visits each item in the list in order: TList[0], then TList[1], then TList[2], and so on until it runs out of items.&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;Removing TList[0] shifts all the other items in the list to the left one slot; the original TList[1] is now TList[0], so the for loop will skip over it.&lt;/P&gt;&lt;P&gt;You can use reverse:&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;for f in reversed(TList):
    # print(os.path.splitext(f)[1])
    if os.path.splitext(f)[1] in ignoreExt:
        # print(f)
        TList.remove(f)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2023 19:24:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/print-files-in-folder-as-arccatalog-sees-them/m-p/1248187#M66546</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2023-01-13T19:24:50Z</dc:date>
    </item>
    <item>
      <title>Re: Print files in folder as ArcCatalog sees them</title>
      <link>https://community.esri.com/t5/python-questions/print-files-in-folder-as-arccatalog-sees-them/m-p/1248189#M66547</link>
      <description>&lt;P&gt;I think the issue may be that you're modifying TList while trying to iterate over it.&amp;nbsp; If you print(f) in every iteration, you'll see that not all of the original items are printed. You should create a new list and append to instead of modifying the existing list.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2023 19:28:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/print-files-in-folder-as-arccatalog-sees-them/m-p/1248189#M66547</guid>
      <dc:creator>JeffreyHolycross</dc:creator>
      <dc:date>2023-01-13T19:28:24Z</dc:date>
    </item>
  </channel>
</rss>

