我在 Azure 中有一个文件共享,其中包含文件夹,而文件夹内又包含许多文件夹。 我试图通过右键单击该文件夹来手动删除该文件夹,该文件夹内有很多文件,并且显示
Failed to delete directory. Error: The specified directory is not empty.
如何删除该目录?需要删除的目录中有数千个文件,无法手动删除每个文件来删除目录
最佳答案
更新:
您可以使用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
}
关于azure - 无法删除 Azure 中的目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63887143/