How do I negate a condition in PowerShell?

后端 未结 4 1803
轻奢々
轻奢々 2020-12-23 08:37

How do I negate a conditional test in PowerShell?

For example, if I want to check for the directory C:\\Code, I can run:

if (Test-Path C:\\Code){
  w         


        
4条回答
  •  佛祖请我去吃肉
    2020-12-23 09:28

    if you don't like the double brackets or you don't want to write a function, you can just use a variable.

    $path = Test-Path C:\Code
    if (!$path) {
        write "it doesn't exist!"
    }
    

提交回复
热议问题