function Remove-BakNRetArchiveStaging { <# .SYNOPSIS 安全拆掉暂存目录:先手工摘掉 junction,再删剩下的普通文件 / 目录。 .DESCRIPTION 绝不能直接 `Remove-Item -Recurse` 了事:那会顺着 junction 走进真实数据里。 这里自己走一遍目录树,遇到连接点只删连接点本身。 #> param([string]$Root) if (-not $Root -or -not (Test-Path -LiteralPath $Root)) { return } $pending = New-Object System.Collections.Generic.Stack[string] $pending.Push($Root) while ($pending.Count -gt 0) { $current = $pending.Pop() foreach ($child in @(Get-ChildItem -LiteralPath $current -Force -ErrorAction SilentlyContinue)) { if ($child.LinkType -eq 'Junction' -or $child.LinkType -eq 'SymbolicLink') { Remove-BakNRetJunction -Path $child.FullName continue } if ($child.PSIsContainer) { $pending.Push($child.FullName) } } } Remove-Item -LiteralPath $Root -Recurse -Force -ErrorAction SilentlyContinue }