Santas
Santas

Reputation: 421

How to pass all files from folder as parameter in PowerShell?

How is it possible to dynamically load all files in folder and pass them as argument to program?

Now I have to do

coffee --bare --join app.js -c utils.coffee app.coffee forum.coffee items.coffee models.coffee activate.coffee chat.coffee

while, all .coffee files should be loaded automatically, so when I add new file I don't have to edit my script.

Thanks

Upvotes: 2

Views: 1341

Answers (3)

zdan
zdan

Reputation: 29450

You can execute your command like this:

&coffee --bare --join app.js -c $(gci *.coffee)

Upvotes: 2

Tomas Panik
Tomas Panik

Reputation: 4619

$arguments = [string]::join(" ",(get-item *.coffee | foreach { $_.Name }))
Invoke-Expression (".\program.exe {0}" -f ($arguments))

Upvotes: 3

rerun
rerun

Reputation: 25505

You can all all of the files to a string using the following

get-childitem *.coffee | Join-String -Separator " "

Then use start-process to invoke the command

EDIT

If you dont have the powershell community extension you can use

[string]::join(" ",(gci))  

Upvotes: 0

Related Questions