Add count condition for a specific extension


I have a script which wait for a specific extension (*.end) in a folder before starting the copy / move function. I’d like a count condition, only start the copy / move only if 2 *.end file are present.

I tried to add .Count -lt 2, in the test-path but it didn’t work

Thank you for your help

$inFolder = 'D:\Desktop\source' 
$outFolder = 'D:\Desktop\dest' 
$backupfolder = 'D:\Desktop\backup' 

Write-Verbose -vb 'attente de *.end'
while (-not (Test-Path "$inFolder/*.end")) { Start-Sleep 1 }

$files = Get-ChildItem -File $inFolder

Write-Verbose -vb 'Attente des fichiers complets'
$files | ForEach-Object {
  do {
    try { [IO.File]::Open($_.FullName, 'Open', 'Read', 'None').Dispose(); return } 
    catch { Start-Sleep 1 }
  } while ($true)

Write-Verbose -vb 'Deplacement'
$files | Copy-Item -Destination $outFolder
$files | Move-Item -Destination $backupfolder


While ($fileCount -ne 2) {
    $fileCount = (Get-ChildItem -Path 'E:\Temp\Files' -Filter *.end).Count
    Start-Sleep -Seconds 1



Great Thank you very much