PowerShell "Test-Path returns false" (case / path separator) in CI
Test-Path reported a path missing even though the file is there. The path string is usually built with the wrong separator, an unescaped wildcard, or a forward-slash assumption that does not resolve.
What this error means
A guard like if (Test-Path $p) takes the wrong branch, then a later step fails because the file was treated as missing (or present). Deterministic for the constructed path.
# file exists at .\dist\app.js, yet:
PS> Test-Path "dist[]/app.js"
False
# the unescaped [ ] is treated as a wildcard character classCommon causes
Wildcard characters in the path
Test-Path treats [, ], *, and ? as wildcards by default. A literal bracket in a path makes it not match unless you use -LiteralPath.
Path built by naive string concatenation
Mixing separators or doubling them when joining strings produces a path Windows does not resolve.
How to fix it
Use -LiteralPath for paths with special characters
Disable wildcard interpretation so brackets and similar characters are treated literally.
if (Test-Path -LiteralPath $p) { Get-Content -LiteralPath $p }Build paths with Join-Path
Let PowerShell pick the separator and avoid manual concatenation bugs.
$p = Join-Path (Join-Path $env:GITHUB_WORKSPACE 'dist') 'app.js'
Test-Path -LiteralPath $pHow to prevent it
- Construct paths with Join-Path and use Test-Path -LiteralPath whenever a path may contain wildcard characters, so existence checks are reliable.