cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

List all files in a Blob Container

asher
New Contributor II

I am trying to find a way to list all files, and related file sizes, in all folders and all sub folders. I guess these are called blobs, in the Databricks world. Anyway, I can easily list all files, and related file sizes, in one single folder, but I can't come up with Python code that lists ALL files and the sizes of each of these files. Just for reference, on a desktop machine the code would look like this.

import sys, os

root = "C:\\path_here\\"

path = os.path.join(root, "targetdirectory")

for path, subdirs, files in os.walk(root):

for name in files:

print(os.path.join(path, name))

Maybe there is a non-Python way to do this. I'd like to get an inventory of all the files in Blob Storage, any way I can.

1 REPLY 1

asher
New Contributor II

from azure.storage.blob import BlockBlobService

block_blob_service = BlockBlobService(account_name='your_acct_name', account_key='your_acct_key')

mylist = [] generator = block_blob_service.list_blobs('rawdata')

for blob in generator:

mylist.append(blob.name)

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!