Skip to content

Instantly share code, notes, and snippets.

@Kagre
Last active January 26, 2021 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kagre/2a556fca93492f1eaebfc8701229564b to your computer and use it in GitHub Desktop.
Save Kagre/2a556fca93492f1eaebfc8701229564b to your computer and use it in GitHub Desktop.
PowerShell - Profile working folder
$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