deleting non empty directory in fileshare in azure storage

pragadeesh.raju 41 Reputation points
2020-07-20T18:17:56.94+00:00

Hello,

I have created a storage account and file share using terraform. And copied few data to the fileshare and it will used by the application for writing the logs.

while deleting the resource , i couldnt delete it as it throws an error as the directory is not empty.

is there work around/solution to delete non empty directories? this will a great option to have

Thanks

Azure Files
Azure Files
An Azure service that offers file shares in the cloud.
1,420 questions
Azure Storage
Azure Storage
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
3,529 questions
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
3,192 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. deherman-MSFT 38,021 Reputation points Microsoft Employee Moderator
    2020-07-20T18:43:34.95+00:00

    @pragadeeshraju-2799 Please try the following and let me know if that resolves your issue:

    Install Azure PowerShell module:

    https://learn.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-2.8.0

    and run below PowerShell commands to close the open handles:

    Connect-AzAccount

    Select-AzSubscription -Subscription <The subscription of the storage account>

    Set-AzCurrentStorageAccount -ResourceGroupName <Resource group of the storage account> -Name <Storage account name>

    Get-AzStorageFileHandle -sharename <file share name>-Recursive | Sort-Object ClientIP,OpenTime

    Example 1: Lists all file shares of current Storage Account, and close all file handles of the file shares recursively.
    Get-AzStorageShare | Close-AzStorageFileHandle -CloseAll -Recursive
    Example 2: Close all file handles on a file
    Close-AzStorageFileHandle -ShareName "mysharename" -Path 'dir1/dir2/test.txt' -CloseAll

    Please see this page for more information. https://learn.microsoft.com/en-us/azure/storage/files/storage-troubleshoot-cannot-delete-files-azure-file-share


    Please do not forget to "Accept the answer" and Upvote on the post that helps you, this can be beneficial to other community members.


  2. deherman-MSFT 38,021 Reputation points Microsoft Employee Moderator
    2020-07-22T17:28:37.357+00:00

    @pragadeesh.raju It sounds like Terraform is trying to delete the contents of the file share before deleting the share. Because the directory is not empty it will not be able to delete it. The solution would be to delete the files either from the mounted share in the OS or API. Alternatively you can skip deleting the files and simply delete the file share, I confirmed this works even with the share mounted and files open.

    ----------------

    Please do not forget to "Accept the answer" and Upvote on the post that helps you, this can be beneficial to other community members.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.