1

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 ?

  • 2
    Try with `-LiteralPath` – Santiago Squarzon May 23 '22 at 13:33
  • 1
    For future reference you might want to avoid [wildcards](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_wildcards?view=powershell-7.2) in your paths or, always use the `LiteralPath` parameter that will interpret the wildcard characters as literal – Santiago Squarzon May 23 '22 at 13:51

1 Answers1

0

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
    "_________"
}