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

前端 未结 7 2189
名媛妹妹
名媛妹妹 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:11

    if (Test-Path C:\DockerVol\SelfCertSSL) {
        write-host "Folder already exists."
    } else {
       New-Item -Path "C:\DockerVol\" -Name "SelfCertSSL" -ItemType "directory"
    }
    

提交回复
热议问题