IF the test-path result is not correct, I don't want to see error mg, instead try max retires and then throw message

  • 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

    }

    Thanks.

  • Check a success flag outside of the loop to output messages.

    Gaz

    -- Stop your grinnin' and drop your linen...they're everywhere!!!

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply