python - 如何循环访问 Azure Databricks 中的 Azure Datalake Store 文件

标签 python azure azure-data-lake databricks

我目前正在使用以下命令成功列出 Azure Datalake Store gen1 中的文件:

dbutils.fs.ls('mnt/dbfolder1/projects/clients')

该文件夹的结构是

- client_comp_automotive_1.json [File]
- client_comp_automotive_2.json [File]
- client_comp_automotive_3.json [File]
- client_comp_automotive_4.json [File]
- PROCESSED [Folder]

我想循环遍历此文件夹中的那些 (.json) 文件并一一处理它们,以便我可以对错误或其他情况采取行动,并将成功处理的文件移动到子文件夹中。

如何在 python 中执行此操作。我已经尝试过

folder = dbutils.fs.ls('mnt/dbfolder1/projects/clients')
files = [f for f in os.listdir(folder) if os.path.isfile(f)]

但这不起作用。 os 未知。如何在 Databricks 中执行此操作?

最佳答案

即使我搜索了两天,答案也很简单:

files = dbutils.fs.ls('mnt/dbfolder1/projects/clients')

for fi in files: 
  print(fi.path)

关于python - 如何循环访问 Azure Databricks 中的 Azure Datalake Store 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51932783/

相关文章:

azure - 复制事件后继续在 Data Lake 中暂存 Blob

python - 两次启动对话时出现空白窗口?

python - 是否有必要使用 SWIG 在接口(interface)文件中提及包装的 .c 文件的所有函数?

php - 从 PHP 执行 Python 脚本

使用 Powershell 中的资源管理器 Azure 发布 Web 应用程序

用于具有多个订阅主题的服务总线的 Azure ARM 模板

Azure 数据湖 gen2 - 验证上传的文件(MD5?)

azure - 如何使用数据工厂截断 Dynamics 365 实体(并复制到 Azure 数据湖)?

python - 来自 .fits 图像的径向轮廓

azure - 将 Azure 磁盘附加到 AKS pod 时出现权限错误