Find 5 files with specified name in folder

Welcome Forums General PowerShell Q&A Find 5 files with specified name in folder

  • This topic has 2 replies, 3 voices, and was last updated 1 week ago by
    Participant
    .
Viewing 2 reply threads
  • Author
    Posts
    • #239261
      Participant
      Topics: 2
      Replies: 0
      Points: -1
      Rank: Member

      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 (“$Path*market*”).

      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

    • #239276
      Participant
      Topics: 12
      Replies: 1642
      Points: 2,660
      Helping Hand
      Rank: Community Hero

      Take a look at Get-ChildItem.

    • #239363
      Participant
      Topics: 6
      Replies: 20
      Points: 68
      Helping Hand
      Rank: Member

      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 = "$Path*sys*"
      Get-Childitem -path $Test -recurse -include *.dll

Viewing 2 reply threads
  • You must be logged in to reply to this topic.