1

I have a binary executable that takes a list of file paths as arguments, e.g.,

C:\Tool.exe C:\Files\File1.txt C:\Files\File2.txt

I would like to call this tool from Powershell. The question is, how can I get the output of get-childitem all on one line?

If I run:

ls C:\Files\*.txt | select FullName

I get one path per line. How can I concatenate the results?

4

1 に答える 1

4

PowerShell 2.0 では、-join 演算子を使用できます。

(ls C:\Files\*.txt | %{ $_.FullName }) -join ' '

PowerShell 1.0 では を設定できます$OFS。これは、一連の項目を文字列として使用するときにそれらを結合するために使用されます。

$ofs = ' '
"$(ls C:\Files\*.txt | %{ $_.FullName })"
于 2009-10-14T18:05:46.700 に答える