Globbing with MinGW on Windows
I have an application built with the MinGW C++ compiler that works something like grep - acommand looks something like this:
myapp -e '.*' *.txt
where the thing that comes after the -e switch is a regex, and the thing after that is file name patter开发者_Go百科n. It seems that MinGW automatically expands (globs in UNIX terms) the command line so my regex gets mangled. I can turn this behaviour off, I discovered, by setting the global variable _CRT_glob
to zero. This will be fine for bash and other sensible shell users, as the shell will expand the file pattern. For MS cmd.exe
users however, it looks like I will have to expand the file pattern myself.
So my question - does anyone know of a globbing library (or facility in MinGW) to do partial command line expansion? I'm aware of the _setargv feature of the Windows CRT, but that expands the full command line. Please note I've seen this question, but it really does not address partial expansion.
I've ended up using conditional compilation to write my own globbing code for the Windows version of my app. This was pretty easy as I have my own CommandLine class which encapsulates argc and argv from main(). Still, I'd be interested to hear of other solutions.
<glob.h>
has glob
and globfree
and lots of flags for glob
.
I'm not sure if I fully understand your problem here, but in Windows you should be able to glob using FindFirstFile / FindNextFile functions from the WIN32 API. Honestly I don't know if their globing capability is comparable to glob() but you could give them a try
精彩评论