cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
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.

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.

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.