I'm looking to optimize this script with a function
$Folder = 'K:\dxf\dxf50000-60000'
$filenames = Get-Content -Path .\files.txt
$missingFilesList = New-object System.Collections.ArrayList
Write-Host "Folder: $folder."
Write-Host "Searching for files"
foreach ($filename in $filenames) {
$found=$false;
Get-ChildItem -Path $Folder -Recurse | ForEach-Object {if($filename -eq $_.BaseName) {Write-Host 'FILE ' $filename ' Ok' -foregroundcolor green; $found=$true;CONTINUE }$found=$false;} -END {if($found -ne $true){ Write-Host 'FILE ' $filename ' missing in the folder' -foregroundcolor red}}
}
Generally I'm looking for files with the same format everytime: basename-revision
51713-0 51762-0 51780-0
Now I also want to search for the basename (i.e 51713) and report this back with the basename and revision if found (and change the color to cyan or something) - what would be the best way to achieve this?
This should work
My C:\files.txt contains the following content:
Outputs the following