'powershell test leaf container fail [duplicate]
with this structure folder :
TEST\
ok.txt
[_]\
a.txt
and the code :
clear
$rep="TEST"
$regex="*"
Get-ChildItem -Path $rep -recurse -Include $regex | ForEach-Object {
"FullName: $($_.FullName) & mode: $($_.Mode)"
Test-Path -Path $_.FullName -PathType Leaf
Test-Path -Path $_.FullName -PathType Container
"_________"
}
I get
FullName: ***\TEST\[_] & mode: d-----
False
False
_________
FullName: ***\TEST\[_]\a.txt & mode: -a----
False
False
_________
FullName: ***\TEST\ok.txt & mode: -a----
True
False
_________
Conclusion :
[] directory : not recognize as Container
[]\a.txt : not recognize as Leaf
but give for both the type Mode (d----- & -a----)
How can I use Leaf & Container to get at least one True ?
Solution 1:[1]
Thanks,
with -LiteralPath it is ok
the program is now :
clear
$rep="TEST"
$regex="*"
Get-ChildItem -Path $rep -recurse -Include $regex | ForEach-Object {
"FullName: $($_.FullName) & mode: $($_.Mode)"
Test-Path -LiteralPath $_.FullName -PathType Leaf
Test-Path -LiteralPath $_.FullName -PathType Container
"_________"
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | user7058377 |
