I'm a bit confused by the -Depth
flag for Get-ChildItem. The following works great (finds all files and folders only one deep under "C:\Program Files"):
dir 'C:\Program Files\' -Depth 1
But if I then want to extend it to find only *.txt type files, I cannot find how to do that (following just give weirdly unexpected output where -Depth 1
is ignored and it instead does the equivalent of a -Recurse
to all subfolders no matter how deep):
dir 'C:\Program Files\*.txt' -Depth 1
dir 'C:\Program Files\' -Include *.txt -Depth 1
dir 'C:\Program Files\*' -Include *.txt -Depth 1
How do we use -Depth
to a specific depth for Get-ChildItem and a required file-pattern?