Last active
January 26, 2021 20:10
-
-
Save Kagre/2a556fca93492f1eaebfc8701229564b to your computer and use it in GitHub Desktop.
PowerShell - Profile working folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$FolderProfile = ([io.directoryinfo]((resolve-path '.').ProviderPath)).GetFileSystemInfos('*',[IO.SearchOption]::AllDirectories) | &{ | |
begin{$r=@{}} | |
process{ | |
$n = resolve-path (split-path $_.FullName) -Relative; | |
$r.$n+=$_.Length | |
} | |
end{$r} | |
}; | |
$Data = $FolderProfile.Keys | sort | &{ | |
begin{'Path,Bytes,Cumulative,Parent'} | |
process{"`"$_`",$($FolderProfile.$_),,`"$(split-path $_)`""} | |
} | ConvertFrom-Csv ` | |
| Add-Member -NotePropertyName Children -NotePropertyValue @() -PassThru | |
$root = $data | ?{$_.Parent -eq '..'} | |
$index = $data | &{begin{$r=@{'.'=$root}}process{$r.($_.Path)=$_}end{$r}} | |
$data | %{try{$index.($_.Parent).Children += $_}catch{}} | |
function Accumulate{ | |
param([parameter(Mandatory=$true,ValueFromPipeline=$true)]$obj) | |
$obj.Cumulative = ($obj.Bytes = [uint64]$obj.Bytes) | |
foreach($c in $obj.Children){ | |
Accumulate $c | |
$obj.Cumulative += [uint64]$c.Cumulative | |
} | |
} | |
$root | Accumulate | |
$data | Format-Table |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment