cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
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

rlgarris
Databricks Employee
Databricks Employee

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)

JosiahYoder
New Contributor III

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)

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group