Powershell Get-Childitem将子目录排除在目录中

时间:2017-01-19 14:48:03

标签: powershell

大家好我的文件夹结构如下

D:\Exclude
     Include
     Include1
         Exclude
         Include 

我需要的是我想过滤目录Include1\Exclude这是我尝试过的不起作用

$Path ="D:\Exclude"
$DirList = Get-ChildItem -Path "$Path" -Recurse | where {$_.DirectoryName -ne "D:\Exclude\Include1\Exclude"}
$DirList

2 个答案:

答案 0 :(得分:5)

使用{{1}}属性而不是目录名,如此。

{{1}}

答案 1 :(得分:0)

使用与你的目录路径相似的方式来排除目录和文件

Get-ChildItem "D:\Exclude" -Recurse | where FullName -NotLike "D:\Exclude\Include1\Exclude\*"


#short version
gci "D:\Exclude" -Rec | ? FullName -NotLike "D:\Exclude\Include1\Exclude\*"