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ş: