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
6

dir -recurse | group-object Extension -noelement

| improve this answer | |
  • I just tried this out. Nice answer! – jftuga Feb 4 '11 at 23:50
  • 1
    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{$_.group|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
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:
| improve this answer | |
  • this is freakin awesome how did u learn to do this? – l--''''''---------'''''''''''' Feb 7 '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 7 '11 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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