微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法删除Azure中的目录

如何解决无法删除Azure中的目录

我在Azure中有一个文件共享,其中包含文件夹,而其中又包含许多文件夹。 我正在尝试通过右键单击文件夹来手动删除文件夹,该文件夹内部有很多文件,并且显示

无法删除目录。错误:指定的目录不为空。

如何删除目录?目录中有数千个文件删除,并且无法手动删除每个文件删除目录

解决方法

更新

您可以使用Azure Storage Explorer(有关安装和使用方法,请参考this article。),然后导航至文件共享->右键单击文件夹->选择删除。这样可以删除非空文件夹。

或者您可以将AzCopy(有关此工具的更多详细信息,请参见here)与azcopy remove命令和--recursive参数一起使用。


原文:

不可能删除azure文件共享中的非空文件夹,您应该首先删除其中的所有文件。

为此,请考虑编写一些代码。还有一个article,它使用powershell删除非空文件夹。这是本文中使用的powershell代码(您也可以在github here中找到源代码):

function RemoveFileDir ([Microsoft.Azure.Storage.File.CloudFileDirectory] $dir,[Microsoft.Azure.Commands.Common.Authentication.Abstractions.IStorageContext] $ctx)
{   
    $filelist = Get-AzStorageFile -Directory $dir
    
    foreach ($f in $filelist)
    {   
        if ($f.GetType().Name -eq "CloudFileDirectory")
        {
            RemoveFileDir $f $ctx #Calling the same unction again. This is recursion.
        }
        else
        {
            Remove-AzStorageFile -File $f           
        }
    }
    Remove-AzStorageDirectory -Directory $dir
    
} 


#define varibales
$StorageAccountName = "Your Storage account name" 
$StorageAccountKey = "Your storage account primary key"
$AzShare = "your azure file share name"
$AzDirectory = "LatestPublish - your directory name under which you want to delete everything; including this directry"
 
 

#create primary region storage context
$ctx = New-AzStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
$ctx.ToString()

#Check for Share Existence
$S = Get-AzStorageShare -Context $ctx -ErrorAction SilentlyContinue|Where-Object {$_.Name -eq $AzShare}

# Check for directory
$d = Get-AzStorageFile -Share $S -ErrorAction SilentlyContinue|select Name

if ($d.Name -notcontains $AzDirectory)
{
    # directory is not present; no action to be performed
    
}
else
{    
    $dir = Get-AzStorageFile -Share $s -Path $AzDirectory    
    RemoveFileDir $dir $ctx    
}
,

只需从与其连接的计算机上将其删除。

Remove-Item -Recurse -Force "your directory"
,

尝试使用 Azure CLI

export CONN_STRING="<YOUR-CONNECTION-STRING>"

az storage share delete \
   --connection-string $CONN_STRING \
   --name filesharename

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。