Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
share|improve this question

migrated from stackoverflow.com May 31 '11 at 8:31

This question came from our site for professional and enthusiast programmers.

    
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. –  pst May 31 '11 at 4:40
    
Here is the "full list" (perhaps) of search terms. –  pst May 31 '11 at 4:47
    
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? –  Pär Björklund May 31 '11 at 11:55
    
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 May 31 '11 at 16:05
    
I found a wonderful resource that can calculate the size of the files technet.microsoft.com/en-us/library/ff730945.aspx –  win7guru Jun 1 '11 at 5:57

1 Answer 1

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".

share|improve this answer
    
I am trying to search from the search bar using specific syntax, such as file:, size:, etc. –  win7guru May 31 '11 at 4:39
    
How about using command line? –  win7guru May 31 '11 at 4:41
    
@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. –  pst May 31 '11 at 4:44
    
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 May 31 '11 at 4:46
    
@Jon rosettacode.org/wiki/Walk_a_directory/Recursively#PowerShell and 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. –  pst May 31 '11 at 4:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.