I was looking through some old PowerShell scripts of mine.
What in the world was this attempting? It appears to be trying to add, multiply and concatenate numbers, and to be reading out the contents of files and directories to the console. Which are completely unrelated and connected by no logic. Why, just why?
Function Examine-Dir($contents, $padding)
{
write-host "Examining folder"
$spacer = "".PadLeft($padding)
Foreach ($file in $contents)
{
$isDir = Test-Path $file -pathtype container
write-host "$spacer Found $file $isDir"
if ($isDir)
{
$childContents = Get-ChildItem $file
$childPadding = 2+$padding
Examine-Dir $childContents $childPadding
}
}
write-host ""
}
Function My-Add($num1, $num2)
{
return $num1 + $num2;
}
Function My-Multiply($num)
{
return $num * $num
}
Function My-Concat($num)
{
return "$num$num"
}
Function Switch-On-User-Choice()
{
write-host " 1) for add"
write-host " 2) for multiply"
write-host " 3) for concat"
$choice = read-host "Please make a choice"
write-host "You typed [ $choice ]"
$starter = 3
switch ($choice)
{
1 { $result = My-Add $starter $choice }
2 { $result = My-Multiply $starter }
3 { $result = My-Concat $starter }
default { $result = "[input not recognized]" }
}
write-host "Starting with $starter, result is $result"
return $result
}
# Start program #################################################
$r = Switch-On-User-Choice
write-host "------returned from function: $r------"
$files = Get-ChildItem
$padding = 2
Examine-Dir $files $padding
I can think of no reason I wrote that, nor what I ever wouldโve done with it.