如何用PowerShell或Batch查找含12个以上文件的目录
找出包含12个以上文件的子目录
PowerShell 实现
Get-ChildItem -Directory | ForEach-Object { $fileCount = (Get-ChildItem -Path $_.FullName -File).Count if ($fileCount -gt 12) { $_.Name } }
- 若要指定目标目录,在
Get-ChildItem -Directory后添加-Path "你的目标目录路径"即可。
Batch 脚本实现
@echo off setlocal enabledelayedexpansion for /d %%d in (*) do ( set "count=0" for %%f in ("%%d\*") do ( if not "%%~af"=="d" set /a count+=1 ) if !count! gtr 12 echo %%d ) endlocal
- 若要指定目标目录,将
for /d %%d in (*)修改为for /d %%d in ("你的目标目录路径\*")即可。
内容的提问来源于stack exchange,提问作者Fabrizio
相关产品推荐
相关产品推荐

