<?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: remove empty folders with pyspark in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/remove-empty-folders-with-pyspark/m-p/105917#M42312</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/93173"&gt;@Nathant93&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;You could use dbutils.fs.ls and iterate on all the directories found to accomplish this task.&lt;/P&gt;
&lt;P&gt;Something like this:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;def find_empty_dirs(path):
    directories = dbutils.fs.ls(path)
    for directory in directories:
        if directory.isDir():
            find_empty_dirs(directory.path)
            contents = dbutils.fs.ls(directory.path)
            if len(contents) == 0:
                # Logic
                dbutils.fs.rm(directory.path, recurse=True)
                print(f"Removed empty directory: {directory.path}")

find_empty_dirs("dbfs:/mnt/your_mount_point")
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 16 Jan 2025 14:26:39 GMT</pubDate>
    <dc:creator>MathieuDB</dc:creator>
    <dc:date>2025-01-16T14:26:39Z</dc:date>
    <item>
      <title>remove empty folders with pyspark</title>
      <link>https://community.databricks.com/t5/data-engineering/remove-empty-folders-with-pyspark/m-p/77495#M35440</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am trying to search a mnt point for any empty folders and remove them. Does anyone know of a way to do this? I have tried dbutils.fs.walk but this does not seem to work.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2024 15:13:47 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/remove-empty-folders-with-pyspark/m-p/77495#M35440</guid>
      <dc:creator>Nathant93</dc:creator>
      <dc:date>2024-07-09T15:13:47Z</dc:date>
    </item>
    <item>
      <title>Re: remove empty folders with pyspark</title>
      <link>https://community.databricks.com/t5/data-engineering/remove-empty-folders-with-pyspark/m-p/78795#M35602</link>
      <description>&lt;P&gt;Unfortunately this says that every folder in my mnt point has a size of 0. I have folders that have folders in which then might contain a metadata file for a streaming checkpoint.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jul 2024 12:41:30 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/remove-empty-folders-with-pyspark/m-p/78795#M35602</guid>
      <dc:creator>Nathant93</dc:creator>
      <dc:date>2024-07-15T12:41:30Z</dc:date>
    </item>
    <item>
      <title>Re: remove empty folders with pyspark</title>
      <link>https://community.databricks.com/t5/data-engineering/remove-empty-folders-with-pyspark/m-p/105917#M42312</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/93173"&gt;@Nathant93&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;You could use dbutils.fs.ls and iterate on all the directories found to accomplish this task.&lt;/P&gt;
&lt;P&gt;Something like this:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;def find_empty_dirs(path):
    directories = dbutils.fs.ls(path)
    for directory in directories:
        if directory.isDir():
            find_empty_dirs(directory.path)
            contents = dbutils.fs.ls(directory.path)
            if len(contents) == 0:
                # Logic
                dbutils.fs.rm(directory.path, recurse=True)
                print(f"Removed empty directory: {directory.path}")

find_empty_dirs("dbfs:/mnt/your_mount_point")
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jan 2025 14:26:39 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/remove-empty-folders-with-pyspark/m-p/105917#M42312</guid>
      <dc:creator>MathieuDB</dc:creator>
      <dc:date>2025-01-16T14:26:39Z</dc:date>
    </item>
  </channel>
</rss>

