I’m having trouble deleting data contained in a folder within a container of a storage account via Azure CLI.
Having a tree of this kind:
Documents
1.0.0
<Files>
2.0.0
<Files>
3.0.0
<Files>
I would like to delete all the folders and files contained in the 3.0.0 folder and leave the others unchanged. How can I do? I’m using az storage blob delete-batch --account-name $account --source $container --pattern '*[/3.0.0/]*' --connection-string $conn-str
but it doesn’t seem to have any effect, all files in container are erased. Some idea?
2
Answers
I saw that
az blob storage
is deprecated and will be eliminated in subsequent versions, in its place I found this instruction https://learn.microsoft.com/en-us/cli/azure/storage/fs/directory?view=azure-cli-latest#az-storage-fs-directory-delete that is right for me, it does exactly what I expect, it deletes a single folder.The Azure CLI az storage blob delete-batch command does not support specifying patterns for deleting blobs within specific folders directly. Instead, you need to specify the blobs you want to delete explicitly.
To delete all blobs within the 3.0.0 folder, you can use a combination of az storage blob delete-batch and az storage blob list commands along with some shell scripting. Here’s how you can do it:
Don’t forget the necessary permissions to perform the delete action.