4

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

example:

1232 JPEG
11 exe
45 bat
2342 avi
532 doc
Alex Gordon
  • 455
  • 3
  • 14
  • 31

2 Answers2

6

dir -recurse | group-object Extension -noelement

Mike Shepard
  • 738
  • 3
  • 7
  • I just tried this out. Nice answer! – jftuga Feb 04 '11 at 23:50
  • 1
    Powershell FTW! Can't be more direct than that. – daveadams Feb 05 '11 at 00: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 05 '11 at 01:07
  • It'd be even more awesome if it supported agrregation without needing to go through `group|foreach{$_.group|foreach{$_|Add-member ...}}` – Joey Feb 05 '11 at 10:49
  • @Joey...I'm not sure what you're trying to accomplish. – Mike Shepard Feb 17 '11 at 22:11
  • mike i don't know if you are still active here but i asked a similar question: http://stackoverflow.com/questions/14614614/displaying-frequency-distribution-of-all-files-recursively-that-were-modified-in – Alex Gordon Jan 30 '13 at 22:03
2

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:
Joey
  • 1,823
  • 11
  • 13
  • this is freakin awesome how did u learn to do this? – Alex Gordon Feb 07 '11 at 15:44
  • 1
    @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 07 '11 at 17:37