I am trying to create a dynamic folder (current date with mm-dd-yyyy)under the blob store. I've tried different resources including this one: How can I safely create a nested directory? and used these guides to attempt to create a dynamic folder, but fail with the following error:
Container_client2 = blob_service_client.create_container(container_name/folder) TypeError: unsupported operand type(s) for /: 'str' and 'str'
Here is the snapshot of my code:
import os
from pathlib import Path
from datetime import datetime
# Instantiate a new BlobServiceClient using a connection string
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient
from azure.core.exceptions import ResourceNotFoundError, ResourceExistsError
today = datetime.now()
try:
connect_str = os.getenv('AZURE_STORAGE_CONNECTION_STRING')
# Create the BlobServiceClient object which will be used to create a container client
# Instantiate a BlobServiceClient using a connection string
blob_service_client = BlobServiceClient.from_connection_string(connect_str)
# Create a unique name for the container
folder = today.strftime('%m-%d-%Y')
container_name = '2021'
print('Folder Name ---> ' + folder)
# Create the container
Container_client1 = blob_service_client.get_container_client(container_name)
Container_client2 = blob_service_client.create_container(container_name/str(folder))
print ("get Container client---" + str(Container_client1))
try:
for blob in Container_client1.list_blobs():
print("Found blob: ", blob.name)
except ResourceNotFoundError:
print("Container not found.")
finally:
print ("nothing")