在 Windows 7 中搜索包含 x 个文件的文件夹?

在 Windows 7 中搜索包含 x 个文件的文件夹?

我想搜索包含一定数量文件的文件夹,但目前我无法弄清楚如何实现此目的的语法。我搜索了 Windows 搜索网站,但只找到了特定于文档的语法。我试图在多个设备之间组织我的文件,但为了查看文件数量而不得不查看每个文件夹变得越来越麻烦。你能帮助我吗?

使用的操作系统:Microsoft Windows 7 Home Premium Edition Service Pack 1(内部版本 7601),64 位更新

$NumFiles = 4
$Directory = (Get-ChildItem "C:\Windows*" -ErrorAction -force)
Get-ChildItem -path $Directory -recurse -include *.exe `
| Sort-Object Name | Format-Table Name, Fullname -auto
$NumFiles + (Get-ChildItem "C:\Windows").Count

答案1

在 C# 中,您可以使用 DirectoryInfo 遍历目录树并获取每个目录中的文件数量。例如:

    DirectoryInfo di = new DirectoryInfo(@"C:\");
    var count = di.GetFiles().LongCount();

您只是想找出两个目录树之间的差异吗?还是想制作同步副本?如果是这样,您可以考虑使用“robocopy”。

相关内容