【发布时间】:2018-09-18 08:14:17
【问题描述】:
要从一个目录中选择每个 AssemblyInfo.cs 减去一个,我运行一个 powershell 脚本:
Clear-Host
$SrcDir = "D:\Projects\Lambda\Sources"
Write-Host $SrcDir
cd $SrcDir
$ExcludeXYZCallStrategy = $SrcDir + "\Lambda.XYZ\XYZCallStrategy\Properties\AssemblyInfo.cs"
# 2. Select Files to be updated
Write-Host $ExcludeXYZCallStrategy
# both these syntaxes fail (tried one after the other not together ofc) :
$Assemblyfiles = Get-ChildItem -Path $SrcDir -Recurse -Include AssemblyInfo.cs -Exclude $ExcludeXYZCallStrategy
$Assemblyfiles = Get-ChildItem -Path $SrcDir -Recurse -Include AssemblyInfo.cs -Exclude D:\Projects\Lambda\Sources\Lambda.XYZ\XYZCallStrategy\Properties\AssemblyInfo.cs
Write-Host $Assemblyfiles
Write-Host "Files Count : " $Assemblyfiles.count
我尝试了不同的语法来强制 Get-ChildItem 排除该文件,但我失败了。
我尝试了这些答案无济于事:
- How to use Get-ChildItem with excluding a list of items with an array in Powershell?
- Get-ChildItem Exclude and File parameters don't work together
从doc,我没有找到任何可以解释为什么不排除该文件的内容。
【问题讨论】:
-
作为一种解决方法,您可以这样做:
| Where-Object {$_.FullName -ne $ExcludeXYZCallStrategy} -
@guiwhatsthat 它有效!谢谢 !但为什么排除不起作用?
-
这只是一个猜测,但我认为 exclude 参数只检查对象的 name 属性,您尝试使用 fullname 属性