need RELIABLE test for null/empty string, please!!
i've been testing with
get folder contents , put them arrays, save arrays
$content = $folder1 + $folder2
$content should empty string '' or have string value containing array data
we want send email if $content has value
if ($content) empty {
exit
else ($content has value)
send email
)
i can not reliably test value of $content
using ps 2.0 on win7 x64 if matters.
really need reliable test empty string resulting no files existing in both folder1 , folder2!!
thank you, tom
if there files returen $files1, $files1 test "true" on if,
so if ($files1 -and $files2) execute if there in both $files1 , $files2.
if either 1 empty if ($files1 -and $files2) return $false, , it's script block not execute.
you can test how variable or expression react in if casting [bool]
ps c:\testfiles> $files1 = gci *.txt
ps c:\testfiles> $files1
directory: c:\testfiles
mode lastwritetime length name
---- ------------- ------ ----
-a--- 5/5/2010 9:24 pm 29 test 1.txt
-a--- 5/5/2010 9:14 pm 29 test.txt
-a--- 5/10/2010 7:29 pm 506 test2_evt.txt
-a--- 4/26/2010 7:46 pm 486086 testa.txt
-a--- 5/21/2010 7:31 am 15 testn.txt
ps c:\testfiles> [bool]$files1
true
ps c:\testfiles> $files2 = gci *.jpg
ps c:\testfiles> $files2
<----no jpg files, $files2 empty/null
ps c:\testfiles> [bool]$files2
false
ps c:\testfiles> [bool]($files1 -and $files2)
false
ps c:\testfiles> [bool]($files1 -or $files2)
true
ps c:\testfiles> $files3 = gci *.csv
ps c:\testfiles> $files3
directory: c:\testfiles
mode lastwritetime length name
---- ------------- ------ ----
-a--- 5/24/2010 8:12 pm 291 12_23_2009_evt.csv
-a--- 5/24/2010 8:12 pm 46134 3_12_2010_evt.csv
-a--- 5/24/2010 8:12 pm 4284 3_13_2010_evt.csv
ps c:\testfiles> [bool]($files1 -and $files3)
true
ps c:\testfiles>
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Windows Server > Windows PowerShell
Comments
Post a Comment