8

My Windows 7 search is pretty slow on one computer and fast on the other. I figured out that one computer has 90,000 files indexed while the other has 1.5 million.

So I'd like to find the biggest folders by number of files, since some are bound to be irrelevant, and exclude them.

I have tools for finding the biggest folders by data size, but not by number of files within. Any ideas?

6 Answers 6

8

If you were using Windows XP, you could use the Folder Size shell-extension which gives you a few columns that you can add to Explorer to show the size of a folder, as well as the number files/folders/both contained therein, thus allowing you to view and sort them right inside Explorer.

Unfortunately, Vista and higher have dropped the API functionality that Folder Size and similar programs use, so they no longer work.

Instead, you’ll have to use a non-shell-extension. Fortunately there are several programs that can do a pretty good job of visualizing space usage on a file-system.

Most of them have a few different modes including text-list/tree (like in Explorer), pie-graph, and treemap, in which the files and sub-directories are represented by squares or rectangles. There should be an option to display the number of files/folders in addition to the size, usually in text-list/tree mode. Sometimes, to get the number of files/folders, you need to select the folder and view its properties (which is less convenient, but still easier than manually in Explorer).

Here are some of the most popular ones (some freeware, others shareware):

2
  • 1
    Yup, WinDirStat is the quickest and easiest because the default view has the number of items right there in the list.
    – Synetech
    Jun 30, 2011 at 0:36
  • 1
    WinDirStat is my favorite too.
    – KCotreau
    Jun 30, 2011 at 1:58
6

And another, TreeSize Free. (In this shot, the directories are named 0-F.)

enter image description here

6

One quick way to get a sorted list of folders by number of files - including subfolders - is:

PowerShell 3+

$a=@{}
Get-ChildItem -LiteralPath 'D:\' -Recurse -Directory -ErrorAction Ignore | Foreach {
    $a[$_.Fullname] = (Get-ChildItem -LiteralPath $_.Fullname -Recurse -File -ErrorAction Ignore).Count
} 
$a.GetEnumerator() | Sort Value -Descending | Format-List

Example output

enter image description here

For those who are interested in how it works

  • Get-ChildItem -LiteralPath 'D:\' -Recurse -Directory loops through all subfolders of a given directory. Change the path to your needs. (-LiteralPath avoids errors from [ and ] brackets.)
  • In each subfolder use (Get-ChildItem -LiteralPath $_.Fullname -Recurse -File).Count to count the number of files including files in subfolders. Folders itself don't count. Only files do.
  • For each subfolder, add a new hash table entry $a[$_.Fullname] = myValue with the current directory as name. As value add our previously mentioned files count
  • After all the work is done, use $a.GetEnumerator() to break the hash table back into multiple items and pipe them to a Sort-Object command which sorts the hash table by value and ascending
1
  • 👍 This executed much faster than I was expecting. Nov 5, 2019 at 22:55
2

I use a program called windirstat which scans through all the files and folders on a drive and gives a nice graphical display of which files or folders are using the most space. You can then move or delete unwanted files and tidy up your disk.

1

Start with Dust 4e1180e5 (2020-08-30), you can now do this like so:

-f, --filecount
Directory 'size' is number of child files/dirs not disk size

Example output:

PS C:\Users\Steven\AppData\Local> dust -f
577            ┌── Default
628          ┌─┴ User Data
629        ┌─┴ Edge
1,154    ┌─┴ Microsoft
1,901    ├── Packages
407      │     ┌── 41ad6w4a.default-release-4
493      │     │   ┌── entries
497      │     │ ┌─┴ cache2
573      │     ├─┴ 7eccqsn1.default-release-1-1597857941226
3,952    │   ┌─┴ Profiles
3,953    │ ┌─┴ Firefox
3,954    ├─┴ Mozilla
3,096    │       ┌── entries
3,100    │     ┌─┴ cache2
3,269    │   ┌─┴ 56uzf1ra.Sunday
10,341   │   │   ┌── entries
10,344   │   │ ┌─┴ cache2
10,428   │   ├─┴ 7nx7hnxa.68-edition-default
13,698   │ ┌─┴ Profiles
13,699   ├─┴ Waterfox
21,181 ┌─┴ .

Since this was just released, I had to build it myself with this command:

$env:RUSTFLAGS = '-C link-arg=-s'
cargo build --release
0

PowerShell script which accepts wildcard directory path and wildcard filenames to display a table of file frequencies sorted by most-to-least. Credit to @nixda for providing a starting point.

$SearchPath='E:\myfolder1\*\myfolder2\'
$FileMatch='*.json'
$a=@{}
 Get-ChildItem $SearchPath -Directory | Foreach {
    $a[$_.Fullname] = (Get-ChildItem $_.Fullname -Recurse -Include $FileMatch).Count
} 
$a.GetEnumerator() | Sort Value -Descending | Format-Table -AutoSize

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .