![](/img/trans.png)
[英]How can I upload a .parquet file from my local machine to Azure Storage Data Lake Gen2?
[英]How do I retrieve all directory paths from Azure Data Lake Storage Gen2 using Python?
我正在尝试使用此处提到的方法检索 Azure Data Lake Storage Gen2 中目录的所有路径。 这是我的代码:
# Connect to account
def initialize_storage_account_ad(storage_account_name, client_id, client_secret, tenant_id):
try:
global service_client
credential = ClientSecretCredential(tenant_id, client_id, client_secret)
service_client = DataLakeServiceClient(account_url="{}://{}.dfs.core.windows.net".format(
"https", storage_account_name), credential=credential)
except Exception as e:
print(e)
# List Directory Contents
def list_directory_contents():
try:
file_system_client = service_client.get_file_system_client(file_system="my-file-system")
paths = file_system_client.get_paths(path="my-directory")
for path in paths:
print(path.name + '\n')
except Exception as e:
print(e)
使用FileSystemClient.get_paths
方法检索文件和目录的路径。
是否有有效的解决方法来检索或过滤目录路径?
请指教。
get_paths
返回一个生成器来列出指定文件系统下的路径(可以是文件或目录),其中还包含每个路径的属性。
path.is_directory == True
有助于区分目录和文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.