Function getFile ($ folder)
{
If (test-path $ folder-pathtype Container)
{
Set-location $ folder
# Write-host "======================================== =========="
$ Spacestring = getSpaceHolder $ folder
# Write-host "$ ($ spacestring) folder: $ folder"
Out-file-FilePath "D: \ PowershellScripts \ MyFavorites.txt"-inputobject "$ ($ spacestring) folder: $ folder"-append
$ Spacecounts = getCharFrequency $ folder
# Write-host "'\ number counts: $ spacecounts"
Get-childitem | foreach-object-process {getFile $ _. FullName}
}
Else
{
$ Spacecounts = getCharFrequency $ folder
$ Spacestring = getSpaceHolder $ folder
# Write-host "$ ($ spacestring) $ folder"
# Write-host "'\ number counts: $ spacecounts"
# Write-host $ folder
Out-file-FilePath "D: \ PowershellScripts \ MyFavorites.txt"-inputobject "$ ($ spacestring) $ folder"-append
}
}
Function getCharFrequency ($ string)
{
$ Frequency = 0
$ Remainstring = $ string
While ($ remainstring. indexof ("\")-gt 0)
{
$ Frequency = $ frequency + 1
$ Remainstring = $ remainstring. substring ($ remainstring. indexof ("\") + 1, $ remainstring. Length-$ remainstring. indexof ("\")-1)
}
Return $ frequency
}
Function getSpaceHolder ($ string)
{
$ SpaceString = ""
$ Frequency = getCharFrequency $ string
$ SpaceHolder = $ Frequency-2
$ IncrementCount = 1
While ($ IncrementCount-lt $ SpaceHolder)
{
$ SpaceString = $ SpaceString + ""
$ IncrementCount = $ IncrementCount + 1
}
Return $ SpaceString
}
Set-location $ args [0]
If (test-path "D: \ PowershellScripts \ MyFavorites.txt") {remove-item "D: \ PowershellScripts \ MyFavorites.txt "}
Get-childitem | foreach-object-process {getFile $ _. FullName}
# Get-childitem | foreach-object-process {write-host $ _. FullName}