PS CTPv2 is finally performant enough with enumerating directories and files that its worthwhile to write deep file system traversal functions. Unix’s du was always incredibly useful for me when managing my files. Here’s the PS equivalent.
1: function du ($path = '.\', $unit="MB", $round=0)
2: {
3: get-childitem $path -force | ? {
4: $_.Attributes -like '*Directory*' } | %{
5: dir $_.FullName -rec -force |
6: measure-object -sum -prop Length |
7: add-member -name Path -value $_.Fullname -member NoteProperty -pass |
8: select Path,Count,@{ expr={[math]::Round($_.Sum/"1$unit",$round)}; Name="Size($unit)"}
9: }
10: }
Sample:
[dronagiri] F:\Vivek\>du .\ –unit MB
Path Count Size(MB)
---- ----- --------
F:\Vivek\Custom UI 275 18
F:\Vivek\Desktop 1151 114
F:\Vivek\Documents 20338 3521
Hope this is useful for your file management.