Specifying wildcard paths for PowerShell

I have a directory structure that is 2 folders deep(e.g. folder1/folder1/file1.txt, folder1/folder2/file1.txt, etc.). I need to traverse the directory structure recursively to extract all the data of the text files and put them in one large text file in the folder above. The command is:

Get-Content .\*\*\*.txt | Out-File ..\whole.txt

Here's the error for this command:

Get-Content : An object at the specified path .\*\*\*.geojson does not exist, or has been filtered by the -Include or
-Exclude parameter.
At line:1 char:1
+ Get-Content .\*\*\*.geojson | Out-File ..\whole_us.geojson
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (System.String[]:String[]) [Get-Content], Exception
    + FullyQualifiedErrorId : ItemNotFound,Microsoft.PowerShell.Commands.GetContentCommand

How do I specify wildcard paths?


have a directory structure that is 2 folders deep(e.g. folder1/folder1/file1.txt, folder1/folder2/file1.txt, etc.). I need to traverse the directory structure recursively to extract all the data of the text files and put them in one large text file in the folder above. The command is:

Get-Content .***.txt | Out-File ..\whole.txt

Here's the error for this command:

Get-Content : An object at the specified path .***.geojson does not exist, or has been filtered by the -Include or -Exclude parameter. At line:1 char:1

How do I specify wildcard paths?

As explained in a comment to your question, it appears that the file extension of the input file does not match the file extension of the file that actually exists. This means that your syntax isn't correct. The description for the -PATH parameter is as follows:

Specifies the path to an item where Get-Content gets the content. Wildcard characters are permitted. The paths must be paths to items, not to containers. For example, you must specify a path to one or more files, not a path to a directory.

You will want to run the following command instead.

Get-Content -PATH .\*\*\*.txt | Out-File ..\whole.txt

The parameters for Get-Content are documented as follows:

Get-Content
   [-ReadCount <Int64>]
   [-TotalCount <Int64>]
   [-Tail <Int32>]
   [-Path] <String[]>
   [-Filter <String>]
   [-Include <String[]>]
   [-Exclude <String[]>]
   [-Force]
   [-Credential <PSCredential>]
   [-Delimiter <String>]
   [-Wait]
   [-Raw]
   [-Encoding <Encoding>]
   [-AsByteStream]
   [-Stream <String>]
   [<CommonParameters>]

Source: Get-Content Syntax