Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Globbing in C++/C, on Windows

Tags:

Is there a smooth way to glob in C or C++ in Windows?

E.g., myprogram.exe *.txt sends my program an ARGV list that has...ARGV[1]=*.txt in it.

I would like to be able to have a function (let's call it readglob) that takes a string and returns a vector of strings, each containing a filename.

This way, if I have files a.txt b.txt c.txt in my directory and readglob gets an argument *.txt, it returns the above filelist.

//Prototype of this hypothetical function.
vector<string> readglob(string);

Does such exist?

like image 628
Paul Nathan Avatar asked Aug 13 '09 00:08

Paul Nathan


People also ask

What is file Globbing?

A glob is a term used to define patterns for matching file and directory names based on wildcards. Globbing is the act of defining one or more glob patterns, and yielding files from either inclusive or exclusive matches.

What is a glob in coding?

In computer programming, glob (/ɡlɑːb/) patterns specify sets of filenames with wildcard characters. For example, the Unix Bash shell command mv *. txt textfiles/ moves ( mv ) all files with names ending in . txt from the current directory to the directory textfiles .

How do you write glob?

The glob pattern to match all files under the /src/tests/ directory should be written as */tests** — where */ denotes matching a string followed by a path separator.

What are the glob characters?

A glob is a string of literal and/or wildcard characters used to match filepaths. Globbing is the act of locating files on a filesystem using one or more globs. The src() method expects a single glob string or an array of globs to determine which files your pipeline will operate on.


1 Answers

Link with setargv.obj (or wsetargv.obj) and argv[] will be globbed for you similar to how the Unix shells do it:

  • http://msdn.microsoft.com/en-us/library/8bch7bkk.aspx

I can't vouch for how well it does it though.

like image 124
Michael Burr Avatar answered Oct 29 '22 17:10

Michael Burr