【发布时间】:2019-03-24 06:25:22
【问题描述】:
我们有一个小脚本,可以创建按每日日期命名的文件夹。我有一个脚本可以删除超过 30 天的文件夹。
dir "\\nas\Backup_old\*" -ErrorAction SilentlyContinue |
Where { ((Get-Date) - $_.LastWriteTime).days -gt 30} |
Get-ChildItem -Recurse | Remove-Item -Recurse -Force
主要是它工作正常。具有竞争的子文件夹将被删除。 但是主文件夹仍然存在,并且 LastWriteTime 被绑定到脚本的运行时。文件夹是空的。有人有解决这个问题的想法吗?
【问题讨论】:
-
我认为你可以查看 fol emty 文件夹和删除文件夹查看这里 hihttps://stackoverflow.com/questions/28631419/how-to-recursively-remove-all-empty-folders-in-powershell
标签: powershell scripting