从电源外壳获取子项结果中排除文件



要从目录中选择每个AssemblyInfo.cs,我运行一个powershell脚本:

Clear-Host
$SrcDir = "D:ProjectsLambdaSources"
Write-Host $SrcDir
cd $SrcDir
$ExcludeXYZCallStrategy = $SrcDir + "Lambda.XYZXYZCallStrategyPropertiesAssemblyInfo.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:ProjectsLambdaSourcesLambda.XYZXYZCallStrategyPropertiesAssemblyInfo.cs
Write-Host $Assemblyfiles
Write-Host "Files Count : " $Assemblyfiles.count

我尝试了不同的语法来强制 Get-ChildItem 排除那个文件,但我失败了。

我尝试了这些答案无济于事:

  • 如何使用 Get-ChildItem 排除在 Powershell 中带有数组的项列表?
  • 获取子项排除和文件参数不能协同工作

从文档中,我没有发现任何可以解释为什么不排除该文件的内容。

由于它只是一个文件,因此您可以使用Where-Object.

$Assemblyfiles = Get-ChildItem -Path $SrcDir -Recurse -Include AssemblyInfo.cs | Where-Object { $_.FullName -ne "D:ProjectsLambdaSourcesLambda.XYZXYZCallStrategyPropertiesAssemblyInfo.cs" }

最新更新