template class Poco::RecursiveDirectoryIterator

Overview

The RecursiveDirectoryIterator class is used to enumerate all files in a directory and its subdirectories. Moreā€¦

#include <RecursiveDirectoryIterator.h>

template <class TTravStr = ChildrenFirstTraverse>
class RecursiveDirectoryIterator
{
public:
    // typedefs

    typedef RecursiveDirectoryIterator<TTravStr> MyType;

    // enums

    enum
    {
        D_INFINITE = 0,
    };

    // construction

    RecursiveDirectoryIterator();

    RecursiveDirectoryIterator(
        const std::string& path,
        UInt16 maxDepth = D_INFINITE
        );

    RecursiveDirectoryIterator(const MyType& iterator);

    RecursiveDirectoryIterator(
        const DirectoryIterator& iterator,
        UInt16 maxDepth = D_INFINITE
        );

    RecursiveDirectoryIterator(
        const File& file,
        UInt16 maxDepth = D_INFINITE
        );

    RecursiveDirectoryIterator(
        const Path& path,
        UInt16 maxDepth = D_INFINITE
        );

    // methods

    const std::string&
    name() const;

    const Poco::Path&
    path() const;

    UInt16
    depth() const;

    UInt16
    maxDepth() const;

    MyType&
    operator=(const MyType& it);

    MyType&
    operator=(const File& file);

    MyType&
    operator=(const Path& path);

    MyType&
    operator=(const std::string& path);

    MyType&
    operator++();

    const File&
    operator*() const;

    File&
    operator*();

    const File*
    operator->() const;

    File*
    operator->();
};

Detailed Documentation

The RecursiveDirectoryIterator class is used to enumerate all files in a directory and its subdirectories.

RecursiveDirectoryIterator has some limitations:

* only forward iteration (++) is supported
* an iterator copied from another one will always
  point to the same file as the original iterator,
  even is the original iterator has been advanced
  (all copies of an iterator share their state with
  the original iterator)

The class can follow different traversal strategies:

* depth-first strategy;
* siblings-first strategy.

The stategies are set by template parameter. There are two corresponding typedefs:

* SimpleRecursiveDirectoryIterator;
* SiblingsFirstRecursiveDirectoryIterator.

The depth of traversal can be limited by constructor parameter maxDepth (which sets the infinite depth by default).

Enum Values

D_INFINITE

Constant for infinite traverse depth.

Construction

RecursiveDirectoryIterator()

Creates the end iterator.

RecursiveDirectoryIterator(
    const std::string& path,
    UInt16 maxDepth = D_INFINITE
    )

Creates a recursive directory iterator for the given path.

RecursiveDirectoryIterator(const MyType& iterator)

Creates a copy of another recursive directory iterator.

RecursiveDirectoryIterator(
    const DirectoryIterator& iterator,
    UInt16 maxDepth = D_INFINITE
    )

Creates a recursive directory iterator for the path of non-recursive directory iterator.

RecursiveDirectoryIterator(
    const File& file,
    UInt16 maxDepth = D_INFINITE
    )

Creates a recursive directory iterator for the given path.

RecursiveDirectoryIterator(
    const Path& path,
    UInt16 maxDepth = D_INFINITE
    )

Creates a recursive directory iterator for the given path.

Methods

const std::string&
name() const

Returns the current filename.

const Poco::Path&
path() const

Returns the current path.

UInt16
depth() const

Depth of recursion (counting from 1).

UInt16
maxDepth() const

Max depth of recursion (counting from 1).