Search for folders with x amount of files in Windows 7?

2

1

I would like to search for folders with a certain number of files, but currently I cannot figure out the syntax on how to achieve this. I have searched the Windows Search site, but have only found document specific syntax. I am trying to organize my files between multiple devices and it is becoming a pain to have to look at each folder, just to see the amount of files. Can you help me?

OS Used: Microsoft Windows 7 Home Premium Edition Service Pack 1 (build 7601), 64-bit Update-

$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

win7guru

Posted 2011-05-31T04:15:40.913

Reputation: 21

I was wondering if anyone who viewed this question, would be willing to give me a "spoonfeedy" answer for this? I'm not fluent in C or powershell, and this is just a one-time thing I'd like to do. Basically I just to search a folder for all subfolders containing 10-or-less files.

What do I download and what's the command? – CreeDorofl – 2015-03-07T03:03:25.880

The Windows 7 search quite simply ... sucks (personal opinion) ... in any case, this requirement is not possible with that tool. FWIW, here is what Microsoft Says.

– None – 2011-05-31T04:40:58.917

Here is the "full list" (perhaps) of search terms.

– None – 2011-05-31T04:47:53.127

what do you mean by organizing files? Are you trying to keep folders synchronized? Are you trying to make sure that you have an even distribution of files in every folder? – Paxxi – 2011-05-31T11:55:17.947

I want to see if there are, for example, 4 files in a folder and that will determine which folder to edit. I basically want to search the folder, find how many files are in it, output the results to a table. – win7guru – 2011-05-31T16:05:16.650

I found a wonderful resource that can calculate the size of the files http://technet.microsoft.com/en-us/library/ff730945.aspx

– win7guru – 2011-06-01T05:57:50.813

Answers

0

From C#, you can use DirectoryInfo to traverse the directory tree as well as obtain the number of files in each directory. For example:

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

Are you just trying to find differences between two directory trees? Or to make a synchronized copy? If so, you might consider using "robocopy".

tofutim

Posted 2011-05-31T04:15:40.913

Reputation: 101

I am trying to search from the search bar using specific syntax, such as file:, size:, etc. – win7guru – 2011-05-31T04:39:02.307

How about using command line? – win7guru – 2011-05-31T04:41:33.880

@Jon With PowerShell or mingw/cygwin, sure. I don't think FIND or any other standard "utility" that comes with windows can search for this though. – None – 2011-05-31T04:44:12.940

Okay, with Powershell ISE, sounds great. Do you have the instructions, or at least a link of where to find how to do it? – win7guru – 2011-05-31T04:46:50.167

@Jon http://rosettacode.org/wiki/Walk_a_directory/Recursively#PowerShell and http://www.computerperformance.co.uk/powershell/powershell_recurse.htm should show how to recurse a file structure. Next step is just to count the 'child items' to determine if the criteria is met.

– None – 2011-05-31T04:51:44.313

I will do my best, I will let you know if I need any more help. Thanks again. – win7guru – 2011-05-31T04:53:21.380

I found a nice resource here as well http://technet.microsoft.com/en-us/library/ee692796.aspx

– win7guru – 2011-05-31T05:29:51.877

I want to set the best answer as one of the comments, how do I do that @pst – win7guru – 2011-06-02T17:15:57.787