<?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: Checking folder within a folder in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/checking-folder-within-a-folder/m-p/1174215#M64561</link>
    <description>&lt;P&gt;Using the &lt;A href="https://docs.python.org/3/library/os.html#os.listdir" target="_self"&gt;os module&lt;/A&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import os

root_dir = r"C:\yourFolderNameHere"
subdir = [
    i for i in os.listdir(root_dir)
    if os.path.isdir(os.path.join(root_dir, i))
]
if subdir:
    # handle having subdirectories&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This will create a Python list with the name of all folders that exist within your root_directory folder. If there are no folders, the result will be an empty list, which is falsy when evaluated with an if statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 16 May 2022 15:52:56 GMT</pubDate>
    <dc:creator>BlakeTerhune</dc:creator>
    <dc:date>2022-05-16T15:52:56Z</dc:date>
    <item>
      <title>Checking folder within a folder</title>
      <link>https://community.esri.com/t5/python-questions/checking-folder-within-a-folder/m-p/1173973#M64554</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to check to see if there are any folders that exist ( empty or with data) within another folder. I am trying to create a custom tool that will check that.&amp;nbsp;&lt;/P&gt;&lt;P&gt;so if there is any folder within a folder, the tool will display some message.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help on creating such a python script will be very helpful: ) thanks!&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 May 2022 00:44:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/checking-folder-within-a-folder/m-p/1173973#M64554</guid>
      <dc:creator>MitchellMoore</dc:creator>
      <dc:date>2022-05-14T00:44:39Z</dc:date>
    </item>
    <item>
      <title>Re: Checking folder within a folder</title>
      <link>https://community.esri.com/t5/python-questions/checking-folder-within-a-folder/m-p/1173976#M64555</link>
      <description>&lt;P&gt;python's os.path, pathlib, glob and arcpy's da.Walk&lt;/P&gt;&lt;P&gt;all have means to traverse a folder structure and return various bits of info (eg list of folders and their files etc)&lt;/P&gt;&lt;P&gt;have a look and see what suits your particular needs&lt;/P&gt;</description>
      <pubDate>Sat, 14 May 2022 02:08:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/checking-folder-within-a-folder/m-p/1173976#M64555</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-05-14T02:08:09Z</dc:date>
    </item>
    <item>
      <title>Re: Checking folder within a folder</title>
      <link>https://community.esri.com/t5/python-questions/checking-folder-within-a-folder/m-p/1173977#M64556</link>
      <description>&lt;P&gt;Hi Dan,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you a lot. I know da.walk can walk top to bottom, but i think my problem is about writing the actual code. like how to do check simply if there is a file folder within a file folder ?&lt;/P&gt;</description>
      <pubDate>Sat, 14 May 2022 02:24:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/checking-folder-within-a-folder/m-p/1173977#M64556</guid>
      <dc:creator>MitchellMoore</dc:creator>
      <dc:date>2022-05-14T02:24:05Z</dc:date>
    </item>
    <item>
      <title>Re: Checking folder within a folder</title>
      <link>https://community.esri.com/t5/python-questions/checking-folder-within-a-folder/m-p/1174215#M64561</link>
      <description>&lt;P&gt;Using the &lt;A href="https://docs.python.org/3/library/os.html#os.listdir" target="_self"&gt;os module&lt;/A&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import os

root_dir = r"C:\yourFolderNameHere"
subdir = [
    i for i in os.listdir(root_dir)
    if os.path.isdir(os.path.join(root_dir, i))
]
if subdir:
    # handle having subdirectories&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This will create a Python list with the name of all folders that exist within your root_directory folder. If there are no folders, the result will be an empty list, which is falsy when evaluated with an if statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2022 15:52:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/checking-folder-within-a-folder/m-p/1174215#M64561</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2022-05-16T15:52:56Z</dc:date>
    </item>
  </channel>
</rss>

