Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

we have a hardrive with hundreds of thousands of files

i need to figure out how many of every file extension we have

how can i do this with windowspowershell or command prompt or what ever else is available??

i need it to go through every directory. this lawyers at my company need this. it can be a total for the entire hardrive it does not have to be broken down by directory


1232 JPEG
11 exe
45 bat
2342 avi
532 doc
share|improve this question
If you want a non-CLI option, this is a very nice tool: – sysadmin1138 Feb 4 '11 at 23:42
You know, of course, that the extension is only a hint. I can name my files any way I like and they will be usable. – Zoredache Feb 5 '11 at 1:57
up vote 6 down vote accepted

dir -recurse | group-object Extension -noelement

share|improve this answer
I just tried this out. Nice answer! – jftuga Feb 4 '11 at 23:50
Powershell FTW! Can't be more direct than that. – daveadams Feb 5 '11 at 0:00
group-object is an awesome cmdlet. it's like "Group by" in SQL except that you don't lose the details (unless you want to, as in this case with -noelement). That is, you can loop through the base objects in each group. – Mike Shepard Feb 5 '11 at 1:07
It'd be even more awesome if it supported agrregation without needing to go through group|foreach{$|foreach{$_|Add-member ...}} – Joey Feb 5 '11 at 10:49
@Joey...I'm not sure what you're trying to accomplish. – Mike Shepard Feb 17 '11 at 22:11

Just because I can: A quick and dirty cmd solution that's not much longer than the PowerShell one:

(for /r %f in (*) do @(set /a EXT:%~xf+=1 >nul 2>&1))&set EXT:
share|improve this answer
this is freakin awesome how did u learn to do this? – l--''''''---------'''''''''''' Feb 7 '11 at 15:44
@I__: I have fun solving complex tasks in archaic or limited languages. Note though that this won't work for two directory trees within the same cmd session since it's all just environment variables I don't reset after use. – Joey Feb 7 '11 at 17:37

Your Answer


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.