Check if file can be found in Windows environment paths

1 min read
This is a simple function that will check if a file can be accessed through environment paths set up in Windows.
Alternative way of presenting the code:
function Test-ExistInEnvPath($fileName) {
$envPaths = ($env:Path -split ';') | Where-Object {$_ -ne ''}
$envPaths | ForEach-Object {
if (Test-Path -Path (Join-Path -Path $_ -ChildPath $fileName)) {
Write-Output $true
} else {
Write-Output $false
}
}
}
Is it possible to change the look of this?
0
Subscribe to my newsletter
Read articles from Øyvind Kallstad directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
