Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

list virtual folders in azure blob storage via python API

I was reading this tutorial but I cannot find a way to list all the (virtual) folder under a container without getting all the files. I have 26K files in 500 (virtual) folders. I just want to get the list of folder without having to wait few minutes to get the output of list_blobs containing the entire file list. Is there a way to do that? or at least tell list_blobs to not go deeper than n levels below a container?

like image 626
Hanan Shteingart Avatar asked Jun 07 '26 19:06

Hanan Shteingart


1 Answers

Perhaps it's not too late for someone. list_blobs doesn't accept a delimiter argument. Instead, use walk_blobs (doc) to get a generator with the files. Using delimiter="/" you will get the next sublevel of files/folders:

For example:

blob_service_client = BlobServiceClient.from_connection_string(file_connect_str)
container_client = blob_service_client.get_container_client(container_name)
for file in container_client.walk_blobs('my_folder/', delimiter='/'):
    print(file.name)

will return:

"my_folder/sub_folder_1/"
"my_folder/sub_folder_2/"
like image 136
Daniel Argüelles Avatar answered Jun 10 '26 09:06

Daniel Argüelles