[prev in list] [next in list] [prev in thread] [next in thread] 

List:       boost
Subject:    [boost] Re: Any interest in a boost::glob() function?
From:       Martin <adrianm () touchdown ! se>
Date:       2004-09-30 19:55:58
Message-ID: loom.20040930T212636-479 () post ! gmane ! org
[Download RAW message or body]

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.




[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic