我目前正在使用以下命令成功列出 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/