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
- you don't know in advance the folder tree
- the file name is unkwnown (except yml extension) The only info you have is
- the file is in a specific folder (i.e. Contract)
- the file as a secific extensioin (i.e. *.yml)
A command such as the following does not work:
Get-ChildItem "C:\temp\FolderLevel01\" -Include "Contract\*.yml" -Recurse
Regards