databricks dbfs是否支持文件元数据,例如文件/文件夹创建日期或修改日期

问题描述 投票:0回答:1

我正在尝试在数据砖笔记本中的目录中进行爬网以查找最新的镶木地板文件。 dbfsutils.fs.ls似乎不支持有关文件或文件夹的任何元数据。 python中是否有其他方法可以做到这一点?数据存储在“ / mnt / foo”下安装到DBFS的蔚蓝数据湖中。任何帮助或指针,表示赞赏。

python databricks azure-data-lake
1个回答
0
投票

在我所知的Azure Databricks上,dbfs路径dbfs:/mnt/foo与Linux路径/dbfs/mnt/foo相同,因此您可以在Python中简单地使用os.stat(path)来获取文件元数据,例如创建日期或修改日期。

os.stat(path)

这是我的示例代码。

enter image description here

结果如下图。

import os from datetime import datetime path = '/dbfs/mnt/test' fdpaths = [path+"/"+fd for fd in os.listdir(path)] for fdpath in fdpaths: statinfo = os.stat(fdpath) create_date = datetime.fromtimestamp(statinfo.st_ctime) modified_date = datetime.fromtimestamp(statinfo.st_mtime) print("The statinfo of path %s is %s, \n\twhich create date and modified date are %s and %s" % (fdpath, statinfo, create_date, modified_date))

© www.soinside.com 2019 - 2024. All rights reserved.