cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
cancel
Showing results for 
Search instead for 
Did you mean: 

how to delete a folder in databricks mnt?

nmud19
New Contributor II

I have a folder at location dbfs:/mnt/temp

I need to delete this folder. I tried using

%fs rm mnt/temp

&

dbutils.fs.rm("mnt/temp")

Could you please help me out with what I am doing wrong?

8 REPLIES 8

User16826991422
Contributor

Hi nmud19,

What error did you get? Can you paste a stack trace?

You may need to make the path absolute and set recursive to true.

dbutils.fs.rm("/mnt/temp", true)

Or, to be more readable:

dbutils.fs.rm(fileprefix+".tmp",recurse=true)

rockssk
New Contributor II

dbutils.fs.rm("/mnt/temp",True)

The command above works in runtime 5.1 with python3

Anonymous
Not applicable

Since you're deleting a folder in the

/mnt
directory, I assume it was made when you mounted a data source. If that's the case, you can delete the folder using

dbutils.fs.unmount("/mnt/temp/")

StefanAlbrecht
New Contributor II

I found the easier way out. It was getting this error all the time: TypeError: '/mnt/adls2/demo/target/' has the wrong type - class bool is expected. Googling helped a lot 😉

Remove files from directory after uploading in Databricks using research paper help in copying files using dbutils

RoyLiga
New Contributor II

try LongPathTool program

SaipradeepSaipr
New Contributor II

how do I delete multiple folders within a mount point ???

amitca71
Contributor II

use this (last raw should not be indented twice...):

def delete_mounted_dir(dirname):

files=dbutils.fs.ls(dirname)

for f in files:

if f.isDir():

delete_mounted_dir(f.path)

dbutils.fs.rm(f.path, recurse=True)

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.