A better way to check if a path exists or not in PowerShell

前端 未结 7 2194
名媛妹妹
名媛妹妹 2020-11-29 20:32

I just don\'t like the syntax of:

if (Test-Path $path) { ... }

and

if (-not (Test-Path $path)) { ... }
if (!(Test-Path $pa         


        
7条回答
  •  无人及你
    2020-11-29 21:14

    This is my powershell newbie way of doing this

    if ((Test-Path ".\Desktop\checkfile.txt") -ne "True") {
        Write-Host "Damn it"
    } else {
        Write-Host "Yay"
    }
    

提交回复
热议问题