SORU
11 Kasım 2011, Cuma


Nasıl powershell'de bir durumu inkar edebilirim?

Nasıl PowerShell koşullu bir test inkar edebilirim? Eğer dizin için kontrol etmek istiyorum örneğin, C:\Code, koşabilirim:

if (Test-Path C:\Code){
  write "it exists!"
}

Bir durum, örneğin (çalışmayan) o inkar etmektir:

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

Geçici çözüm:

if (Test-Path C:\Code){}
else {
  write "it doesn't exist"
}

Bu gayet iyi çalışıyor, ama bir satır içi tercih ederim.

CEVAP
11 Kasım 2011, Cuma


Neredeyse Not vardı. Olmalıdır:

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

Ayrıca!kullanabilirsiniz: if (!(Test-Path C:\Code)){}

Sadece eğlence için, aynı zamanda en okunabilir/anlaşılabilir bir yöntem olmasa da bit düzeyinde özel veya kullanabilirsiniz.

if ((test-path C:\code) -bxor 1) {write "it doesn't exist!"}

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Mark Hyder

    Mark Hyder

    6 EKİM 2011
  • STITCHLESS TV how to sew your own style tutorials

    STITCHLESS T

    9 HAZİRAN 2011
  • The Onion

    The Onion

    14 Mart 2006

İLGİLİ SORU / CEVAPLAR