windows:如何删除包含少于X个文件的所有文件夹

问题描述 投票:0回答:1

我有一个包含很多子文件夹的文件夹(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
    }
}
windows directory
1个回答
0
投票
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
}

}

© www.soinside.com 2019 - 2024. All rights reserved.