Find 5 files with specified name in folder

Hello,

I am trying to write one of my first PS scripts that will search for specified files (5 of them) in given path.

I tried below solution but can’t concatenate $Path parameter with the name of the file with wildcards ("$Pathmarket").

So first of my questions is:

  1. How to concatenate string parameter with another string with wildcards?
  2. What would be better solution to search for those files?
$Path = "C:\Users\lucas\Documents\Reporting system\test\" For ($i=1;$i -le 5;$i++){ If ($i -eq 1){ $Test = Test-Path -path "$Path*market*" -Include *.txt Write-Host $Test "market" } ElseIf ($i -eq 2) { $Test = Test-Path -path "'$Path*man_rep*" -Include *.txt Write-Host $Test "man_rep" } ElseIf ($i -eq 3) { $Test = Test-Path -path "$Path*noshow_market_split*" -Include *.txt Write-Host $Test "noshow" } ElseIf ($i -eq 4) { $Test = Test-Path -path "$Path*market_gross*" -Include *.txt Write-Host $Test "marekt_gross" } Else { $Test = Test-Path -path "$Paths*revenue*" -Include *.txt Write-Host $Test "revenue" } }

 

Regards

Take a look at Get-ChildItem.

I don’t quite understand your issue as posted. I tested “your concatenation” with wildcards and didn’t have any problem, it worked. I added -recurse because you used $Test as a -path, therefor the presumption that the files of interest will be below the top folder string $Test.

$Path = ‘c:\windows’
$Test = “$Pathsys
Get-Childitem -path $Test -recurse -include *.dll