One of the most interesting features of the Path library is the ability to use wildcards in Paths. For example,
Path p1("*.c"); Path p2("[a-z]*"); Path p3("/bin/?(?)sh");
These wildcards remain uninterpreted by the Path library until an explicit expand_wildcards is performed.
List<Path> dotcs, a_zs, shells; p1.expand_wildcards(dotcs); p2.expand_wildcards(a_zs); p3.expand_wildcards(shells);
The list of Paths returned consists of the Paths representing all those files in the underlying file system which match the given pattern according to the Korn shell pattern matching rules. Notice that the Korn shell pattern matching rules are used regardless of which shell the user is actually running.
The function expand_wildcards does not perform the ``tilde expansion'' at the beginning of a path. That functionality is provided by expand_tilde.
Path p1("~/myfile"); p1.expand_tilde(); // "/my/home/directory/myfile" Path p2("~stan/stansfile"); p2.expand_tilde(); // "/stans/home/directory/stansfile"
The value of ``/my/home/directory'' is taken from the current value of $HOME, while the value of ``/stans/home/directory'' is gotten from
(see getpwnam(3). If the path does not begin with a tilde, then expand_tilde has no effect.
If the user wants to expand both tildes and wildcards, tilde expansion should be done first.
Path p("~/*.c"); p.expand_tilde(); // "/my/home/directory/*.c" List<Path> mydotcs; p.expand_wildcards(mydotcs); // mydotcs now has the value // "( /my/home/directory/foo.c // /my/home/directory/bar.c )"
Expanding wildcards without first expanding the tilde is probably a mistake, since the tilde will remain uninterpreted.
Path p("~/*.c"); List<Path> mydotcs; p.expand_wildcards(mydotcs); // l is "( ~/*.c )"