Just use Powershell, which is preinstalled on Windows 7.
Powershell is capable of running cmd commands and does understand wildcards at any place in a path.
To start Powershell just type "powershell" in your start menu search box and hit enter.
In case the application expects a string with all filenames in it this is the right script:
$delimiter = " "
[string]$files = $nothing ; ls *.txt | % { $files += $_.fullname + $delimiter } ; application.exe $files
Change $delimiter = " " to $delimiter = "," if your application expects a comma separated list of file names.
Explanation of code:
[string]$files = $nothing - creates an empty variable of type string
; - is a separator for multiple commands, not a pipeline!
ls *.txt | % { $files += $_.fullname + $delimiter } - gets a list of all text files and creates a string with all filenames separated by the delimiter
application.exe $files - calls the application and passes the file list to it
You can even search for a file pattern recursively by adding -recurse to ls *.txt so the complete code would look like this:
$delimiter = " "
[string]$files = $nothing ; ls *.txt -recurse | % { $files += $_.fullname + $delimiter } ; application.exe $files
Edit:
To avoid irritations, ls and dir are aliases of Get-ChildItem and % is an alias to ForEach-Object. I keep my code with aliases used because it's shorter.
EDIT 2018/04/25:
Back in 2012 I've been fairly new to PowerShell. Of course there is an easier way though it's not as easy as unix/linux' capability of glob expansion:
app.exe $(ls *.txt | % {$_.FullName})
Explanation:
- $() will evaluate the expression inside first and will replace itself
with the output of that expression (much like backticks do in bash)
ls *.txt gets FileInfo objects of all files that match the glob
*.txt
- because PowerShell is object oriented, we have to output the
fullname of each FileInfo object. Simply naming an attribute/property
in PowerShell outputs it by default.
% { $_.FileName } does that for us. % loops over all elements returned by ls and outputs each objects FileName.
I suspect the answer will be no, but has anyone dealt with this or come up with any way to make this easier?Actually, I’m having the opposite problem, I am trying to figure out a way to get the command-interpreter to treat its list as strings and prevent it from inreptreting them as wildcards. For example,for %i in (foobar baz really?) do @echo %iwill treat the last item (really?) as a filename wildcard, and skip it if there are no files namedreally1,reallyz, etc. ☹ – Synetech Feb 4 '13 at 18:19?is not a legal character for filenames in the Windows filesystem. The character can only be interpreted as a wildcard. See Naming Files, Paths, and Namespaces on MSDN and Using wildcard characters in TechNet. – jww Jul 29 '15 at 4:33