https://delta.io logo
s

sabari dass

07/19/2023, 11:28 AM
Hi All, Is there any way to delete the non empty folder using
dbutils
command in Databricks? Can anyone plz help me on this?
d

Dominique Brezinski

07/19/2023, 1:42 PM
Yes their is a second parameter to rm that when set true will recursively delete.
s

sabari dass

07/19/2023, 1:45 PM
Yeah I tried it but it’s not working
dbutils.fs.rm(“mnt_loc”,True) but I am getting below error. Error: shaded.databricks.org.apache.hadoop.fs.azure.AzureException: hadoop_azure_shaded.com.microsoft.azure.storage.StorageException: This operation is not permitted on a non-empty directory.
d

Dominique Brezinski

07/19/2023, 2:01 PM
Oh, I have no experience on Azure. That may be a semantic of that storage system.
👍 1
e

Edouard

07/19/2023, 2:29 PM
Is mnt_loc a mount point ?
s

sabari dass

07/19/2023, 2:31 PM
Yes it’s a mount point location
e

Edouard

07/19/2023, 2:54 PM
I haven’t try it yet, but let’s try a step by step debug. I guess you should try to delete a folder under your mount point (i.e. /mnt_loc/folderA). This way you could check if the problem is that you cannot rm a whole mount point location.
s

sabari dass

07/19/2023, 3:21 PM
I can delete the same folder using below cmd but when I try using dbutils it’s not working %fs rm -r <mnt loc>
e

Edouard

07/19/2023, 3:37 PM
Oh i see. I cannot reproduce this behaviour. And when I try to delete a non-empty folder I encounter this error
Java.io.IOException: Non-recursive delete of non-empty directory
but no StorageException.
👍 1