0
votes

To select every AssemblyInfo.cs from a directory minus specifically one, I run a powershell script :

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

I tried different syntaxes to force Get-ChildItem to exclude that one file but I failed.

I tried these these answers to no avail :

From the doc, I found nothing that would explain why the file is not excluded.

1
As a workaround you could to this: | Where-Object {$_.FullName -ne $ExcludeXYZCallStrategy}guiwhatsthat
@guiwhatsthat It works ! thanks ! but why exclude is not working ?Poutrathor
It's just a guess but I think the exclude parameter only checks the name property of the object and you tried to use the fullname propertyguiwhatsthat

1 Answers

3
votes

Since it's only one file, you could use Where-Object.

$Assemblyfiles = Get-ChildItem -Path $SrcDir -Recurse -Include AssemblyInfo.cs | Where-Object { $_.FullName -ne "D:\Projects\Lambda\Sources\Lambda.XYZ\XYZCallStrategy\Properties\AssemblyInfo.cs" }