0

我想从 Azure Files 中读取一个文件(使用 ShareClient 成功)并将该文件导出到 Azure blob 存储。

首先,我使用以下代码将容器安装在 Databricks 中:

def mount(container, account_name):
    """Mount a container in blob storage"""
    mount_list = [_.mountPoint for _ in dbutils.fs.mounts()]
    mount_point = f"/mnt/{container}/"
    if mount_point not in mount_list:
        dbutils.fs.mount(
                source = f"wasbs://{container}@{account_name}.blob.core.windows.net/",
                mount_point = mount_point,
                extra_configs = {f"fs.azure.account.key.saweaaedwh.blob.core.windows.net":dbutils.secrets.get(scope = "KEY-WE-AAE-DWH", key = f"key-{account_name}")})
        print(f"Container {container} is successfully mounted")
    else:
        print("Container is already mounted")

当我想使用以下代码上传文件时:

with open(f"/dbfs/mnt/datascience/spc/failed2/test.txt", "wb") as outfile:
    download_stream = file_client.download_file()
    outfile.write(download_stream.readall())

出现以下错误消息:

FileNotFoundError: [Errno 2] No such file or directory: '/dbfs/mnt/datascience/spc/failed2/test.txt'

为了创建这个目录,我使用了这个代码:

dbutils.fs.mkdirs('/mnt/datascience/spc/failed2/test.txt')

问题是这也会创建“空”目录。如果目录至少包含 1 个文件,您知道如何仅创建目录吗?

在此处输入图像描述

4

0 回答 0