I have a folder containing the following files:
- File_1.txt
- File_2.txt
- AnotherFile.txt
I want to be able to achieve an output of: File_1.txt - File_2.txt
I have tried running:
ls .\file*.txt | %{$_.Name}
which returns what I want except on separate lines, how can I join the files returned by a given character (-
in this example)?
Any help is appreciated.
You can use the
-join
operator:If you need more control about the individual items being joined here, just amend the pipeline appropriately:
i'd do:
ls .\file*.txt | Foreach { $output = $output + $_ + ' - '}