Skip to content

Commit 11ad7f4

Browse files
tasherif-msftrakshith91
authored andcommitted
Clean up batch delete sample (Azure#15898)
* cleaned up batch delete sample * fixed spacing
1 parent da23e4f commit 11ad7f4

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed
Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from azure.storage.blob import BlobServiceClient, ContainerClient
1+
from azure.core.exceptions import ResourceExistsError
2+
from azure.storage.blob import BlobServiceClient
23
import os
34

45
"""
@@ -13,27 +14,29 @@
1314

1415
SOURCE_FOLDER = "./sample-blobs/"
1516

17+
1618
def batch_delete_blobs_sample(local_path):
17-
# Set the connection string and container name values to initialize the Container Client
19+
# Set the connection string and container name values to initialize the Container Client
1820
connection_string = os.getenv('AZURE_STORAGE_CONNECTION_STRING')
1921

2022
blob_service_client = BlobServiceClient.from_connection_string(conn_str=connection_string)
21-
# Create a ContainerClient to use the batch_delete function on a Blob Container
23+
# Create a ContainerClient to use the batch_delete function on a Blob Container
2224
container_client = blob_service_client.get_container_client("mycontainername")
2325
try:
2426
container_client.create_container()
2527
except ResourceExistsError:
2628
pass
27-
# Upload blobs
29+
# Upload blobs
2830
for filename in os.listdir(local_path):
2931
with open(local_path+filename, "rb") as data:
3032
container_client.upload_blob(name=filename, data=data, blob_type="BlockBlob")
3133

32-
# List blobs in storage account
34+
# List blobs in storage account
3335
blob_list = [b.name for b in list(container_client.list_blobs())]
34-
35-
# Delete blobs
36+
37+
# Delete blobs
3638
container_client.delete_blobs(*blob_list)
3739

38-
if __name__ == '__main__':
40+
if __name__ == '__main__':
3941
batch_delete_blobs_sample(SOURCE_FOLDER)
42+

0 commit comments

Comments
 (0)