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 ???
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:
az storage blob delete-batch --source test --account-name blobstorage0516 --pattern '[!user&&!people]*'
The structure of my container is as below after I run the command.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With