问题描述
我在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