Reputation: 8646
Hi all I have my folder structure as follows
D:\Exclude
Include
Include1
Exclude
Include
What I need is I would like to filter the directory Include1\Exclude
this is what I tried which is not working
$Path ="D:\Exclude"
$DirList = Get-ChildItem -Path "$Path" -Recurse | where {$_.DirectoryName -ne "D:\Exclude\Include1\Exclude"}
$DirList
Upvotes: 3
Views: 6537
Reputation: 17492
use a like with path of your dir to exclude dir and file
Get-ChildItem "D:\Exclude" -Recurse | where FullName -NotLike "D:\Exclude\Include1\Exclude\*"
#short version
gci "D:\Exclude" -Rec | ? FullName -NotLike "D:\Exclude\Include1\Exclude\*"
Upvotes: 1
Reputation: 13567
Use the .FullName
property instead of Directory name, like so.
dir $path -Recurse | measure | select Count
Count
-----
4
PS C:\users\Stephen> dir $path -Recurse | ? FullName -ne "R:\Exclude\Include1\Exclude" |
>> measure | select Count
Count
-----
3
Upvotes: 5