I tried in my environment and got the below results:
I want to get a list of all the folders from the registered datastore in Azure ML studio.
Datastores are attached to workspaces and are used to store connection information to Azure storage services
In machine learning, the blob container or file share is the datastores.
Initially, you can see my data stores it has two folders:

To list the folders only from blob storage(datastores).
you can use the azure-storage-blob package and below code :
from azure.storage.blob import BlobServiceClient
connect_str="<Your connection string>"
container_name="your container name(Datastore)"
blob_service_client = BlobServiceClient.from_connection_string(connect_str)
container_client = blob_service_client.get_container_client(container_name)
for file in container_client.walk_blobs(delimiter="/"):
print(file.name)
Output:
The above code is executed successfully, and it returns the folder name only.
folder1/
folder2/

If you need to access the folders with files you can use the below code:
Code:
from azure.storage.blob import BlobServiceClient
connect_str="your connection string"
container_name="containername(datastore)"
blob_service_client = BlobServiceClient.from_connection_string(connect_str)
container_client = blob_service_client.get_container_client(container_name)
for file in container_client.list_blobs():
print(file.name)
Output:
The above code is executed successfully and returns the folder with the file name.
folder1/28-03-2023.html
folder1/subfolder1/20-03-2023.html
folder2/sas.txt
