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

╄→гoц情女王★ 提交于 2020-03-23 06:30:29

问题


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 ???


回答1:


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.

  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.



来源:https://stackoverflow.com/questions/57713726/azure-cli-storage-blob-delete-batch-to-delete-all-blobs-excluding-two-directori

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!