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:ย 

delete files from the directory

db-avengers2rul
Contributor II

Is there a way to delete recursively files using a command in notebooks

since in the below directory i have many combination of files like .txt,,png,.jpg but i only want to delete files with .csv

example dbfs:/FileStore/.csv*

1 ACCEPTED SOLUTION

Accepted Solutions

UmaMahesh1
Honored Contributor III

Hi @Rakesh Reddy Gopidiโ€‹ 

You can use the os module to iterate over a directory.

By using a loop over the directory, you can check what the file ends with using .endsWith(".csv).

After fetching all the files, you can remove it.

Hope this helps..

Cheers.

Uma Mahesh D

View solution in original post

2 REPLIES 2

db-avengers2rul
Contributor II

%fs rm -r dbfs:/FileStore/.csv*

dbutils.fs.rm('dbfs:/FileStore/.csv*', True)

is this correct ?

UmaMahesh1
Honored Contributor III

Hi @Rakesh Reddy Gopidiโ€‹ 

You can use the os module to iterate over a directory.

By using a loop over the directory, you can check what the file ends with using .endsWith(".csv).

After fetching all the files, you can remove it.

Hope this helps..

Cheers.

Uma Mahesh D

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