Search code examples
azureazure-blob-storageazure-cliazure-storage-account

Azure CLI - az storage blob delete-batch pattern


I have a container called container1 in my Storage Account storageaccount1, with the following files:

blobs/tt-aa-rr/data/0/2016/01/03/02/01/20.txt  
blobs/tt-aa-rr/data/0/2016/01/03/02/02/12.txt  
blobs/tt-aa-rr/data/0/2016/01/03/02/03/13.txt  

blobs/tt-aa-rr/data/0/2016/01/03/03/01/10.txt

I would like to delete the first 3, for that I use the following command:

az storage blob delete-batch --source container1 --account-key XXX --account-name storageaccount1 --pattern 'blobs/tt-aa-rr/data/0/2016/01/03/02/*' --debug

The files are not deleted and I see the following log:

urllib3.connectionpool : Starting new HTTPS connection (1): storageaccount1.blob.core.windows.net:443
urllib3.connectionpool : https://storageaccount1.blob.core.windows.net:443 "GET /container1?restype=container&comp=list HTTP/1.1" 200 None

What is wrong with my pattern?

If I try to delete file by file it works.


Solution

  • As stated in comments, you are not able to apply patterns to subfolders, only first level folders, as documented here. But if you want, you can easily write a script to list the blobs in your container, using the prefix to filter them az storage blob list and then apply the delete for each of the result blobs.