我有一个包含很多子文件夹的文件夹(AI实验和每个参数更改都会生成一个新文件夹,有时只有1或2个文件)。如何删除包含少于 X 个文件的所有文件夹?
还没有尝试任何东西,因为不知道;) 编辑:找到解决方案:
Get-ChildItem -Directory -Recurse -Depth 5 | ForEach-Object {
$directory = $_.FullName
$fileCount = (Get-ChildItem $directory | Measure-Object).Count
if ($fileCount -le 10) {
Remove-Item -Recurse -Force $directory
}
}
Get-ChildItem -Directory -Recurse -Depth 5 | ForEach-Object {
$directory = $_.FullName
$fileCount = (Get-ChildItem $directory | Measure-Object).Count
if ($fileCount -le 10) {
Remove-Item -Recurse -Force $directory
}
}