Can't Delete folder inside File Share

Handian Sudianto 6,096 Reputation points
2024-02-20T01:16:32.9366667+00:00

Hello, I want to delete one folder (ARCHIVE) inside the share folder on azure but i always error "Failed to delete directory 'xxxxxx'. Error: The specified resource may be in use by an SMB client. RequestId:9763c6e5-901a-00b3-6299-6366e2000000 Time:2024-02-20T01:12:32.1386635Z" I can make sure there are no client connected to this folder, how i can delete this? User's image

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
0 comments No comments
{count} votes

Accepted answer
  1. TP 124.7K Reputation points Volunteer Moderator
    2024-02-20T03:43:50.7+00:00

    Hi,

    You can use commands similar to below to close open file handles using Azure Cloud Shell:

    $ctx = New-AzStorageContext -StorageAccountName "mystorageacctname" -StorageAccountKey "<account key>"
    Close-AzStorageFileHandle -ShareName "mysharename" -Path 'archive' -Recursive -CloseAll -Context $ctx -PassThru
    
    

    After the file handles are closed, you should be able to delete the folder.

    Please click Accept Answer and upvote if the above was helpful.

    Thanks.

    -TP


1 additional answer

Sort by: Most helpful
  1. Sumarigo-MSFT 47,466 Reputation points Microsoft Employee Moderator
    2024-02-20T07:54:15.85+00:00

    @Handian Sudianto Welcome to Microsoft Q&A Forum, Thank you for posting your query here! Can you check any other client accessing the share? Create another test file in the same storage account(fileshare) for testing purpose and see are facing the similar issue?

    The issue is caused because of the SharingViolation due to the specified resource may be in use by an SMB client.

    Azure - Clearing the lock on a file within an Azure File Share Based on the error message you may refer to this article: https://learn.microsoft.com/en-us/rest/api/storageservices/managing-file-locks which provides detailed information on file locks Try to Unlock all Azure file share locks This article lists common problems that are related to Microsoft Azure Files when you connect from Windows clients. It also provides possible causes and resolutions for these problems. In addition to the troubleshooting steps in this article: Unable to delete files Sharingviolation: The operation failed because the object is already opened and does not allow the sharing mode that the caller requested. Additional details: Cannot delete full directory structure from Directory in File Share
    deleting non empty directory in fileshare in azure storage Please let us know if you have any further queries. I would like to work closer on this issue.

    ---Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you**, this can be beneficial to other community members.**

    0 comments No comments

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.