Probably a bit late for the program you are working on, but here's how you could do it using Mono.Options
static void Main(string[] args)
{
//let's try this mono.options thing shall we?
string xapfile = null;
var files = new List<string>();
var p = new Mono.Options.OptionSet()
{
{ "xap=", v => xapfile =v },
{ "file:", v => files.Add(v)}
};
List<string> extra = p.Parse(args);
Console.WriteLine(@"
xap = '{0}',
file(s)= {1}",
xapfile,
string.Join(",", files.ToArray())
);
Console.WriteLine(@"
left overs: {0}",
string.Join(Environment.NewLine, extra.ToArray())
);
// rest of your Main here
Calling syntax would be
myapp.exe --file="file 1" --file="file 2" --file="file 3"
You could even forgo the whole files variable and just treat the left overs as the files, and call it like myapp.exe "file 1" "file 2" "file 3"
and pluck the files out of the extra list.
Mono.Options is pretty powerful. You don't even have to use --, it appears you can use /file=
or -file=
Unfortunately, Windows doesn't do globbing for you (unless you're passing the options to a powershell cmdlet), so you have to do it yourself. It's pretty easy though, here's a bit of code I've used in the past to expand *.foo
or "c:\temp\*.bar|c:\temp\*.txt"
Also, unless you wrap the filenames in talkies, I probably wouldn't comma separate the list, as comma is valid in a filename. You know that one is going to bite you one day :-) Pipe makes a good choice, but only if you wrap the whole expression in talkies, otherwise windows thinks you're doing piping. Ah, the joys of command line processing :-)