Boost logo

Boost :

Subject: Re: [boost] [filesystem] #6521 Directory listing using C++11 range-based for loops
From: Dave Abrahams (dave_at_[hidden])
Date: 2012-04-20 09:27:29


on Fri Apr 20 2012, Beman Dawes <bdawes-AT-acm.org> wrote:

> On Fri, Apr 20, 2012 at 5:24 AM, Thorsten Ottosen
> <thorsten.ottosen_at_[hidden]> wrote:
>> On 20-04-2012 10:12, Thorsten Ottosen wrote:
>>>
>>> On 19-04-2012 17:29, Beman Dawes wrote:
>>
>>
>
>>> then we could add
>>>
>>> boost::iterator_range<...>
>>> boost::directory_range( const boost::path& )
>>> boost::iterator_range<...>
>>> boost::recursive_directory_range( const boost::path& )
>>
>>
>> Then, if we wanted to make a really user-friendly interface, we could add
>>
>> boost::iterator_range<...>
>> boost::directory_range( const boost::path&, const boost::path& extension )
>>
>> support for multiple extensions or reguar expression would be cool, e.g.
>>
>>   boost::directory_range( "some_path/", "(.txt|.doc|.jpg)" )
>
> Cool!
>
> But:
>
>> and support for the reverse sitution
>>
>> boost::iterator_range<...>
>> boost::directory_range( const boost::path&, const boost::regex& toExclude )
>
> is even better:-)

So, add Boost.Parameter and you get

    directory_range('some_path', _recursive=true, _include=string_or_regex, _exclude=string_or_regex)
    directory_range('some_path', _exclude=string_or_regex)
    directory_range('some_path', _recursive=false)

>> Especially for recursive iteration, it is useful to skip entire directories.
>
> Mind-blowing! Your suggestion is getting very close to a solution for
> the general directory search problem I've wrestled with for years.
>
> What we would really like is to be able to apply a series of filters,
> some of which apply to directories, some to files. Examples are your
> include|exclude regex filters, applicable to directories|files|both.
> Another filter might be a file filter <=|>= a given size. Dates and
> permissions filters would also be useful. Perhaps user supplied
> filters. And how about filters applied to the contents of files?

And then there's

    directory_range('some_path') | filtered(predicate1) | filtered(predicate2) ...

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

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