I noticed that Test-Path has some apparent strange behaviour when checking if a folder exists. Basically, if the folder actually exists, Test-Path correctly identifies the folder for -PathType Container as one would hope. However, if I append an ‘x’ or ‘X’ to the end of the path where no such folder actually exists, Test-Path still returns True. This only seems to happen with the ‘x’ character (upper or lowercase). I wasn’t aware that ‘x’ was a special character? I haven’t seen any info to suggest it is. Maybe I’missing something. Please check the code below.
[string]$LogOutputFolder1 = "C:\Work\Automation" Test-Path -Path $LogOutputFolder1 -PathType Container #True Test-Path -Path $LogOutputFolder1 -PathType Leaf #False Test-Path -Path $LogOutputFolder1 -PathType Any #TrueFolder/Path does not exist
[string]$LogOutputFolder1 = “C:\Work\Automationx”
Test-Path -Path $LogOutputFolder1 -PathType Container #True
Test-Path -Path $LogOutputFolder1 -PathType Leaf #False
Test-Path -Path $LogOutputFolder1 -PathType Any #TrueFolder/Path does not exist
[string]$LogOutputFolder1 = “C:\Work\AutomationX”
Test-Path -Path $LogOutputFolder1 -PathType Container #True
Test-Path -Path $LogOutputFolder1 -PathType Leaf #False
Test-Path -Path $LogOutputFolder1 -PathType Any #TrueFolder/Path does not exist
[string]$LogOutputFolder1 = “C:\Work\Automationy”
Test-Path -Path $LogOutputFolder1 -PathType Container #False
Test-Path -Path $LogOutputFolder1 -PathType Leaf #False
Test-Path -Path $LogOutputFolder1 -PathType Any #FalseFolder/Path does not exist
[string]$LogOutputFolder1 = “C:\Work\Automationxx”
Test-Path -Path $LogOutputFolder1 -PathType Container #False
Test-Path -Path $LogOutputFolder1 -PathType Leaf #False
Test-Path -Path $LogOutputFolder1 -PathType Any #False