Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure CLI: storage blob delete-batch to delete all blobs excluding two directories

I have a PowerShell script that currently deletes all blobs in my $web container.

az storage blob delete-batch --account-name myaccountname --source $web

This works great, but now I want to exclude two directories from being deleted. I've looked over the documentation and I'm still not sure how the exclusion syntax is supposed to look.

I'm certain that I have to use the --pattern parameter.

The pattern used for globbing files or blobs in the source. The supported patterns are '*', '?', '[seq]', and '[!seq]'.

I'm hoping someone can let me know what the value of the --pattern param should look like so that I can delete everything in the $web container except the blobs in the /aaa and /bbb directories.

az storage blob delete-batch --account-name myaccountname --source $web --pattern ???

like image 611
Tom Faltesek Avatar asked Aug 29 '19 15:08

Tom Faltesek


1 Answers

According to my test, if you want to parameter --pattern to exclude a directory from being deleted, you can use the expression '[[!]]'

az storage blob delete-batch --source <container_name> --account-name <storage_account_name> --pattern '[!<folder name>]*'

For example:

  1. The structure of my container is as below before I run the command.

enter image description here

  1. Run the command
    az storage blob delete-batch --source test --account-name blobstorage0516 --pattern '[!user&&!people]*'
  1. The structure of my container is as below after I run the command.

    enter image description here

like image 114
Jim Xu Avatar answered Sep 28 '22 07:09

Jim Xu