【发布时间】:2020-10-28 06:45:12
【问题描述】:
我已连接到 Azure 存储,需要获取文件名。我编写了一个函数,它可以获取特定目录中的内容列表。
datepath = np.datetime64('today').astype(str).replace('-', '/')
def list_directory_contents():
try:
file_system_client = service_client.get_file_system_client(file_system="container_name")
paths = file_system_client.get_paths(path = "folder_name/" + str(datepath))
for path in paths:
print(path.name + '\n')
except Exception as e:
print(e)
然后我调用函数
list_directory_contents()
这给了我类似的东西
folder_name/2020/10/28/file_2020_10_28.csv
现在我只想从上面提取文件名,即“file_2020_10_28.csv”
【问题讨论】:
-
你试过``` for path in paths: print(path.name.split("/")[-1] + '\n')```