3

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
1
  • Do your folder names really like Exclude and include? Commented Jan 19, 2017 at 17:49

2 Answers 2

5

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
Sign up to request clarification or add additional context in comments.

1 Comment

Note that if you are try to also filter out files in the exclude folder you will need to change it to FullName -notlike "D:\Exclude\Include1\Exclude*"
1

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\*"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.