How do I achieve this in Windows using either Command-prompt or PowerShell?
myprog *
EDIT: I want to call myprog with each file in the current directory as an argument.
How do I achieve this in Windows using either Command-prompt or PowerShell?
myprog *
EDIT: I want to call myprog with each file in the current directory as an argument.
Do you mean the following construct in command shell (cmd.exe):
for %f IN (*.*) DO echo %f
If your goal is to call "myprog.exe" for each file in a directory, assuming that "myprog.exe" does not handle wildcards by itselef, it should be something like that in powershell :
dir | % {prog $_.FullName}
Edit : taking your comment into account, try this :
prog (get-childItem -name)
Hope it helps...
I wrapped Cédric Rup's solution in a function ea (ExpandAll?). Not as clean as the Unix approach though.
function ea ($p="*") { dir $p | foreach { '"{0}" ' -f $_.Name } }
.\Myprog.exe (ea)
.\Myprog.exe (ea *)
.\Myprog.exe (ea *.txt)
In a .CMD or .BAT file:
SETLOCAL EnableDelayedExpansion
FOR %%f in (*) DO SET params=!params! "%%f"
CALL myprog %params%
The SETLOCAL EnableDelayedExpansion
and !variable!
syntax allow you to accumulate the results. (See this page for explanation and examples.)
Edit: Added quotes around the %%f, and changed the listing to be '*'... see comments below.