Im trying to create a script where it delete all the file in the blob when the creation date of the file > 15 days. i’m able to delete the blob using the code below but i coudn’t find a way to access creation date from azure and then delete the file
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient, __version__
storage_account_key = "KEY"
storage_account_name = "STORAGE NAME"
connection_string = "connection STRING "
container_name = "Connection String"
blob_name="blob storage
container_client = ContainerClient.from_connection_string(conn_str=connection_string,
container_name=container_name)
container_client.delete_blob(blob=blob_name)
2
Answers
What you need to do is get the blob properties using
BlobClient.get_blob_properties()
method. Once you get theproperties
, you can find the blob’s created date/time increation_time
property.Your code would be something like:
Adding to @Gaurav Mantri, Below is the code where you can check if the creation date is greater than 15 days and delete if it is.
RESULTS: