Reputation: 137524
I would like users to be able to run my program (from Windows cmd) with syntax like this
app.exe *.pdf
app.exe February/*.pdf March/*.pdf
app.exe contracts.pdf
The app would then do its business for each of the relevant files. In Unix this is called globbing and it's done by the shell.
How can I achieve this for a Windows C# command line app?
Hypothetical syntax
void Main(string[] args)
{
foreach(var file in args.SelectMany(arg => Glob.Expand(arg)))
{
Process(file)
}
}
Upvotes: 0
Views: 940
Reputation: 71
take a look at NuGet package Microsoft.Extensions.FileSystemGlobbing
https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.filesystemglobbing.matcher
Upvotes: 1
Reputation: 29632
The easiest way to do this is to convert the command line parameter into a regular expression. See glob pattern matching in .NET for an example on how to convert the command line argument into a regular expression.
Upvotes: 0