无法删除Azure中的目录
我在Azure中有一个文件共享,其中包含文件夹,反过来又包含许多文件夹。 我试图删除一个文件夹手动右键点击文件夹,其中有这么多的文件,它说 无法删除目录。错误:指定的目录不是空的无法删除Azure中的目录,azure,file,azure-storage,azure-files,azure-storage-files,Azure,File,Azure Storage,Azure Files,Azure Storage Files,我在Azure中有一个文件共享,其中包含文件夹,反过来又包含许多文件夹。 我试图删除一个文件夹手动右键点击文件夹,其中有这么多的文件,它说 无法删除目录。错误:指定的目录不是空的 如何删除目录?目录中有数千个文件要删除,不能手动删除每个文件以删除目录只需将其从所连接的计算机中删除即可 Remove-Item -Recurse -Force "your directory" 更新: 您可以使用Azure存储资源管理器(请参阅如何安装和使用它),然后导航到您的文件共享->右键单
如何删除目录?目录中有数千个文件要删除,不能手动删除每个文件以删除目录只需将其从所连接的计算机中删除即可
Remove-Item -Recurse -Force "your directory"
更新: 您可以使用Azure存储资源管理器(请参阅如何安装和使用它),然后导航到您的文件共享->右键单击文件夹->选择删除。这可以删除非空文件夹 或者您可以将
AzCopy
(有关此工具的更多详细信息,请参阅)与命令和--recursive
参数一起使用
原件: 无法删除azure文件共享中的非空文件夹,应首先删除其中的所有文件 请考虑为此编写一些代码。还有一个使用powershell删除非空文件夹的。以下是本文中使用的powershell代码(您也可以在github中找到源代码): 尝试使用
导出连接字符串=“”
az存储共享删除\
--连接字符串$CONN_字符串\
--名称filesharename
如果您不想使用code删除非空文件夹,则可以使用工具Azure Storage Explorer
或AzCopy
。请参阅下面的答案以了解更多详细信息。在给出的所有答案中,我尝试了使用Azcopy命令删除非空文件夹,效果非常好。
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
}
export CONN_STRING="<YOUR-CONNECTION-STRING>"
az storage share delete \
--connection-string $CONN_STRING \
--name filesharename