Powershell中的Get-ChildItem -Recurse当前以级别顺序方式遍历目录。有什么办法可以在Powershell中以后置方式遍历目录?
我正在尝试删除早于某些时间的文件。删除文件后,如果子文件夹为空,则也删除该文件夹。现在正在这样做。
$path = 'D:\Files'
Get-ChildItem -Path $path -Recurse | Where-Object {
(($_.LastWriteTime -lt (Get-Date).AddDays(-30)) -and ($_ -is [system.io.fileinfo]) )
} | Remove-Item
Get-ChildItem -Path $path -Recurse | Where-Object {
($_ -is [System.IO.DirectoryInfo]) -and $_.CreationTime -lt (Get-Date).AddDays(-30) -and ((Get-ChildItem $_.FullName).Count -eq 0)
} | Remove-Item -Force
Run Code Online (Sandbox Code Playgroud)
但是我想用一个命令来做。不能作为两个不同的命令。