Hi,
I'm having a strange behaviour in a script I'm creating. The purpose of the script is to update some files in some folders. In the case that more folders need to use the script, I'm importing the folders name and path from a CSV file (much easier to read it from there instead of hardcoding the folders in the code). As you can see, I add a number at the beginning of the folder's name, and then I let them choose which folder number do they want to update.
# Import from CSV File $name = @() $path = @() $bkpPath = @() Import-Csv $AppsFile | ForEach-Object { $name += $_.Name $path += $_.Path $bkpPath += $_.bkpPath } Write-Host "Choose the folder to update:" Write-Host "" $count = 1 foreach ($n in $name) { Write-Host $count " - " $n $count += 1 } Do {$opt = read-host -prompt "Enter the option number"} Until ($opt -lt $count -AND $opt -gt 0)
The problem appears when I started debuging the script, and try to input strange characters. The idea of the "Do - Until" statement, is that the user enters a loop until they choose a correct option. It works ok when it doesn't let you input letters, or numbers outside the range I'm using.
The strange behaviour appears when I enter for example "0." (The important part is the DOT after the zero). There, it sends me to the last option in my CSV file. If I put "<number>.", it reads it as if it were "<number>". And if I input a number out of range plus a final dot, it breaks my script (instead of just keep looping as it's supposed to).
Does anyone even understand the issue? =P It's really strange, I don't know if there is another way to limit the input...
Thanks,
Regards