How to find biggest folders (by number of files) in Windows
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):
- SequoiaView
- WinDirStat
- Space
- FolderSize
And another, TreeSize Free. (In this shot, the directories are named 0-F.)
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
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 aSort-Object
command which sorts the hash table by value and ascending