Boost logo

Boost :

From: Martin (adrianm_at_[hidden])
Date: 2004-09-30 14:55:58


Hi Angus,

Both your solutions will work ofcourse but I think it solves the problem in
the wrong end.

Why not drop the dependency on fs:directory_iterator and solve the problem at
the root.

My suggestion is that you create your own iterators.

1. filtered_directory_iterator. A simple filter that matches leafs in one
directory only using '*' & '?' only. Filtering can also be on files and
directories.

filtered_directory_iterator(const path& p, const char* pattern, enum {
{no_filter, no_files, no_directories, no_devices...} filter);

This would solve all problems with case sensitivity since you pass the pattern
direct to filesystem (findfirstfile) (glob() is needed for posix). It would
also be a "cheap" operation for the most common case like finding all files in
a directory: filtered_directory_iterator(p, "*", ~no_files)

2. glob_iterator. A regex based iterator which might even recurse down
directories to find matches. Personally I can't really see the application for
a regex file search so you know the requirement better than I do.

- I have one further question for you, however. If the 'top level'
- pattern doesn not contain any wild cards (foo.cpp in ../*/foo.cpp),
- then I use
- fs::path const candidate = working_dir /= predicate.file();
- if (exists(candidate)
- matches.push_back(candidate);
-
- So, will 'exists' do the right thing here?

Don't know. "exists" only return false if the filesystem says "no such file
exist". If the filesystem says "access denied" the files is assumed to exist
but I don't know what happens if you are not allowed to descend working_dir.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk