Hello,
IF the test-path result is not correct, I don't want to see error mg, instead try max retires and then throw message.
clear-host
function checkfilelocation()
{
$retrycount = 0
$retries = 5
$val = 0
#$args.ErrorAction = "Stop"
while ($val -ne 5)
{
try
{
$PATH = read-host "Enter the complete path to read from the file: [i.e. ""C:\test\filepath.ini""; Dont include "" ""]"
IF($PATH -ne '')
{
write-host $PATH -ForegroundColor red
IF (-NOT (Test-Path -path $PATH))
{
#Throw "$($PATH) is not a valid folder"
$val++;
write-host $bol -ForegroundColor red
}
}
else{
write-host "Retry the path of the file once more!!" -ForegroundColor red
#write-host $val;
$val++;
}
print $val
}
catch [System.Exception]
{
write-host "Error."
write-host $error[0].Exception.ToString()
throw
}
}
write-host "You did not enter the path of the file. So BREAKING.." -ForegroundColor CYAN
}