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)

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group