Warm tip: This article is reproduced from serverfault.com, please click

Azure Databricks: How to delete files of a particular extension outside of DBFS using python

发布于 2020-12-03 13:01:25

I am able to delete a file of a particular extension from the directory /databricks/driver using the bash command in databricks.

%%bash

rm /databricks/driver/file*.xlsx

But I am unable to figure out, how to access and delete a file outside of dbfs in a python script,

I think using dbutils we cannot access files outside of DBFS and the below command outputs False as its looking in DBFS.

dbutils.fs.rm("/databricks/driver/file*.xlsx")

I am eager to be corrected.

Questioner
Somu Sinhhaa
Viewed
0
Somu Sinhhaa 2020-12-07 17:24:02

Not sure how to do it using dbutils but I am able to delete it using glob

import os
from glob import glob

for file in glob('/databricks/driver/file*.xlsx'):
  os.remove(file)