Sat*_*era 7 python azure azure-data-lake azure-databricks
我试图获取天蓝色数据湖中存在的每个文件的最后修改时间。
文件= dbutils.fs.ls('/mnt/blob')
对于文件中的 fi: print(fi)
输出:-FileInfo(路径='dbfs:/mnt/blob/rule_sheet_recon.xlsx',名称='rule_sheet_recon.xlsx',大小=10843)
在这里我无法获取文件的最后修改时间。有什么办法可以得到这个财产吗?
我尝试下面的 shell 命令来查看属性,但无法将其存储在 python 对象中。
%sh ls -ls /dbfs/mnt/blob/
输出:- 总计 0
0 -rw-r--r-- 1 root root 13577 九月 20 日 10:50 a.txt
0 -rw-r--r-- 1 root root 10843 九月 20 日 10:50 b.txt
我们没有直接的方法来获取这些详细信息。但是我们根据以下简单的 python 代码获得了这些详细信息。
示例:考虑一下,您想要获取 adls 路径container_name/container-Second中的所有子目录和文件 --- 您可以使用以下代码
from pyspark.sql.functions import col
from azure.storage.blob import BlockBlobService
from datetime import datetime
import os.path
block_blob_service = BlockBlobService(account_name='account-name', account_key='account-key')
container_name ='container-firstname'
second_conatainer_name ='container-Second'
#block_blob_service.create_container(container_name)
generator = block_blob_service.list_blobs(container_name,prefix="Recovery/")
report_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
for blob in generator:
length = BlockBlobService.get_blob_properties(block_blob_service,container_name,blob.name).properties.content_length
last_modified = BlockBlobService.get_blob_properties(block_blob_service,container_name,blob.name).properties.last_modified
file_size = BlockBlobService.get_blob_properties(block_blob_service,container_name,blob.name).properties.content_length
line = container_name+'|'+second_conatainer_name+'|'+blob.name+'|'+ str(file_size) +'|'+str(last_modified)+'|'+str(report_time)
print(line)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
16422 次 |
最近记录: |