Only 4Info
Only 4Info

Reputation: 31

Powershell - Using wildcards in path to search for filename in a specific subfolder

Extension of the post Powershell - using wildcards to search for filename

Hi There!

Let's assume we have this files and folders configuration:

C:\temp\FolderLevel01\FolderLevel02\FolderLevel03\level03.txt
C:\temp\FolderLevel01\FolderLevel02\FolderLevel03\level03.yml
C:\temp\FolderLevel01\FolderLevel02\FolderLevel03\FolderLevel04\level04.txt
C:\temp\FolderLevel01\FolderLevel02\FolderLevel03\FolderLevel04\level04.yml
C:\temp\FolderLevel01\FolderLevel02\FolderLevel03\FolderLevel04\Contract\contract.txt
C:\temp\FolderLevel01\FolderLevel02\FolderLevel03\FolderLevel04\Contract\contract.yml

We can retrieve the contract.yml file if we have the correct folder tree structure in the "Path" argument:

Get-ChildItem "C:\temp\FolderLevel01\FolderLevel02\FolderLevel03\FolderLevel04\Contract\" -Include "*.yml" -Recurse
Get-ChildItem "C:\temp\FolderLevel01\*\*\*\Contract\" -Include "*.yml" -Recurse
Get-ChildItem "C:\temp\FolderLevel01\*\*\*\Contract\*.yml"

But how to retrieve the "Contract\*.yml" if

A command such as the following does not work:

Get-ChildItem "C:\temp\FolderLevel01\" -Include "Contract\*.yml" -Recurse

Regards

Upvotes: 3

Views: 3663

Answers (1)

Paolo
Paolo

Reputation: 26014

In two steps:

$folder=(Get-ChildItem .\FolderLevel01\\Contract -Recurse)
$file=(Get-ChildItem ($folder.FullName + '\*.yml'))

Upvotes: 1

Related Questions