Azure CLI:storage blob delete-batch 删除除两个目录之外的所有 blob

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

我有一个 PowerShell 脚本,当前删除我的 $web 容器中的所有 blob。

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

效果很好,但现在我想排除两个目录被删除。我查看了 the documentation,但我仍然不确定排除语法应该是什么样子。

我确定我必须使用 --pattern 参数。

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

我希望有人能告诉我 --pattern 参数的值应该是什么样子,这样我就可以删除 $web 容器中的所有内容,除了 /aaa 中的 blob 和/bbb 个目录。

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

根据我的测试,如果你想参数--pattern排除一个目录被删除,你可以使用表达式'[[!]]'

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

例如:

  1. 在我 运行 命令之前,我的容器结构如下。

  1. 运行命令
    az storage blob delete-batch --source test --account-name blobstorage0516 --pattern '[!user&&!people]*'
  1. 我的容器结构在我运行命令后如下。