Skip to content

Instantly share code, notes, and snippets.

@PadreSVK
Created December 14, 2018 20:03
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 PadreSVK/3106457d2a8209eea6547b7c23964bbc to your computer and use it in GitHub Desktop.
Save PadreSVK/3106457d2a8209eea6547b7c23964bbc to your computer and use it in GitHub Desktop.
PS script for create dirt tree rows for my semestral thesis
function CreateDirtTree($folderRoot, $level)
{
if(-not $(Test-Path $folderRoot))
{
Write-Error "Path do not exist"
return
}
if(-not $level){
$level = 1
}
$items = New-Object System.Collections.ArrayList;
$childItems = ls -Path $folderRoot
foreach ($item in $childItems) {
$size = [math]::Round($($item.length/1KB))
if($size -eq 0){
$size = 1
}
if($item -is [System.IO.DirectoryInfo]){
$items += ("`t" * $($level-1)) + ".$level "+ $item.Name + "."
$dirItems = CreateDirtTree -folderRoot $item.FullName -level $($level + 1)
$dirItems | %{ $items += $_ }
}
else{
$items += ("`t" * $level) + ".$level "+ $item.Name +".\DTcomment{" + $size + " KB}."
}
}
return $items
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment