I will try my best to ask the question.
Here is an abstract of the function.
Dim testPath = "Test-Path 'H:GeneralH5841"
Dim removeDir = "Remove-Item 'H:GeneralH5841"
result = RunScript($"{testPath}{payType}_{payrunNum}_{trials}_{ProcessingDate_DTP.Text}'")
If String.Compare(result, "True") Then
RunScript($"{removeDir}{payType}_{payrunNum}_{trials}_{ProcessingDate_DTP.Text}'")
Output_RTB.Text = "Folder Deleted"
Else
Output_RTB.Text = "Folder Not Found"
End If
First, the function tests if the path is valid. Below is what the result will equal and it is working in Powershell, true if folder is found, else false. This is working.
Test-Path 'H:GeneralH5841G7_999_Final_29.03.24'
However, say when I tests it, the folder exists, and I run this function, it deletes the folder and prompts Folder Deleted but when I try to simulate that the folder is not there, it returns as False but it still shows Folder Deleted, instead of Folder Not Found.
When I start off without creating the folder, it returns False and Folder Not Found. I am not sure why this is behaving like this.
I also tried the conventional way of result is “True” and it is also behaving like the aforementioned. I used MsgBox to prompt the result variable and also used a textbox to test for white spacing and it appears none.
If result Is "True" Then
RunScript($"{removeDir}{payType}_{payrunNum}_{trials}_{ProcessingDate_DTP.Text}'")
Output_RTB.Text = "Folder Deleted"
Else
Output_RTB.Text = "Folder Not Found"
End If
p.s The curly braces are string interpolation that grab strings from variables and form controls in VB.net before converting into a powershell command.
Do you know why VB.net does not do logical comparrison properly or is there a different approach I can take?
Thanks in advance