且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用dbutils在Databricks中上传后,从目录中删除文件

更新时间:2023-12-04 20:04:52

如果要从路径'/ mnt / adls2 / demo / target /'删除所有文件

if you want to delete all files from the path '/mnt/adls2/demo/target/'

有一个简单的方法命令

dbutils.fs.rm('/ mnt / adls2 / demo / target /',True)

无论如何,如果您要使用代码,请查看dbutils 文档

Anyway if you wanto to use your code take a look in dbutils doc!

rm(dir:字符串,递归:boolean = false) :boolean->删除文件或目录

您的代码具有更多参数

dbutils.fs.rm(files [i] .path,'/ mnt / adls2 / demo / target /'+ file)

我认为您不需要这部分,'/ mnt / adls2 / demo / target /'

I think you don't need this part ,'/mnt/adls2/demo/target/'

因此您的新代码可以为

for i in range (0, len(files)):
    file = files[i].name
        if now in file:  
            dbutils.fs.rm(files[i].path + file, True)
            print ('copied     ' + file)
        else:
            print ('not copied ' + file)