JUCE  v6.1.6 (6.0.8-1114)
JUCE API
Looking for a senior C++ dev?
I'm looking for work. Hire me!
juce::RangedDirectoryIterator Class Referencefinal

Allows iterating over files and folders using C++11 range-for syntax. More...

#include <juce_RangedDirectoryIterator.h>

Collaboration diagram for juce::RangedDirectoryIterator:

Public Types

using difference_type = std::ptrdiff_t
 
using iterator_category = std::input_iterator_tag
 
using pointer = void
 
using reference = DirectoryEntry
 
using value_type = DirectoryEntry
 

Public Member Functions

 RangedDirectoryIterator ()=default
 The default-constructed iterator acts as the 'end' sentinel. More...
 
 RangedDirectoryIterator (const File &directory, bool isRecursive, const String &wildCard="*", int whatToLookFor=File::findFiles, File::FollowSymlinks followSymlinks=File::FollowSymlinks::yes)
 Creates a RangedDirectoryIterator for a given directory. More...
 
bool operator!= (const RangedDirectoryIterator &other) const noexcept
 Returns the inverse of operator==. More...
 
const DirectoryEntryoperator* () const noexcept
 Return an object containing metadata about the file or folder to which the iterator is currently pointing. More...
 
RangedDirectoryIteratoroperator++ ()
 Moves the iterator along to the next file. More...
 
DirectoryEntry operator++ (int)
 Moves the iterator along to the next file. More...
 
const DirectoryEntryoperator-> () const noexcept
 
bool operator== (const RangedDirectoryIterator &other) const noexcept
 Returns true if both iterators are in their end/sentinel state, otherwise returns false. More...
 

Private Member Functions

void increment ()
 
bool next ()
 

Private Attributes

DirectoryEntry entry
 
std::shared_ptr< DirectoryIterator > iterator
 

Detailed Description

Allows iterating over files and folders using C++11 range-for syntax.

In the following example, we recursively find all hidden files in a specific directory.

std::vector<File> hiddenFiles;
for (DirectoryEntry entry : RangedDirectoryIterator (File ("/path/to/folder"), isRecursive))
if (entry.isHidden())
hiddenFiles.push_back (entry.getFile());

@tags{Core}

Member Typedef Documentation

◆ difference_type

◆ iterator_category

using juce::RangedDirectoryIterator::iterator_category = std::input_iterator_tag

◆ pointer

◆ reference

◆ value_type

Constructor & Destructor Documentation

◆ RangedDirectoryIterator() [1/2]

juce::RangedDirectoryIterator::RangedDirectoryIterator ( )
default

The default-constructed iterator acts as the 'end' sentinel.

◆ RangedDirectoryIterator() [2/2]

juce::RangedDirectoryIterator::RangedDirectoryIterator ( const File directory,
bool  isRecursive,
const String wildCard = "*",
int  whatToLookFor = File::findFiles,
File::FollowSymlinks  followSymlinks = File::FollowSymlinks::yes 
)

Creates a RangedDirectoryIterator for a given directory.

The resulting iterator can be used directly in a 'range-for' expression.

Parameters
directorythe directory to search in
isRecursivewhether all the subdirectories should also be searched
wildCardthe file pattern to match. This may contain multiple patterns separated by a semi-colon or comma, e.g. "*.jpg;*.png"
whatToLookFora value from the File::TypesOfFileToFind enum, specifying whether to look for files, directories, or both.
followSymlinksthe policy to use when symlinks are encountered

Member Function Documentation

◆ increment()

void juce::RangedDirectoryIterator::increment ( )
private

Referenced by operator++().

◆ next()

bool juce::RangedDirectoryIterator::next ( )
private

◆ operator!=()

bool juce::RangedDirectoryIterator::operator!= ( const RangedDirectoryIterator other) const
inlinenoexcept

Returns the inverse of operator==.

References operator==().

◆ operator*()

const DirectoryEntry& juce::RangedDirectoryIterator::operator* ( ) const
inlinenoexcept

Return an object containing metadata about the file or folder to which the iterator is currently pointing.

References entry.

◆ operator++() [1/2]

RangedDirectoryIterator& juce::RangedDirectoryIterator::operator++ ( )
inline

Moves the iterator along to the next file.

References increment().

◆ operator++() [2/2]

DirectoryEntry juce::RangedDirectoryIterator::operator++ ( int  )
inline

Moves the iterator along to the next file.

Returns
an object containing metadata about the file or folder to to which the iterator was previously pointing.

References juce::gl::result.

◆ operator->()

const DirectoryEntry* juce::RangedDirectoryIterator::operator-> ( ) const
inlinenoexcept

References entry.

◆ operator==()

bool juce::RangedDirectoryIterator::operator== ( const RangedDirectoryIterator other) const
inlinenoexcept

Returns true if both iterators are in their end/sentinel state, otherwise returns false.

References iterator.

Referenced by operator!=().

Member Data Documentation

◆ entry

DirectoryEntry juce::RangedDirectoryIterator::entry
private

Referenced by operator*(), and operator->().

◆ iterator

std::shared_ptr<DirectoryIterator> juce::RangedDirectoryIterator::iterator
private

Referenced by operator==().


The documentation for this class was generated from the following file:
juce::DirectoryEntry::getFile
File getFile() const
The path to a file or folder.
Definition: juce_RangedDirectoryIterator.h:39
juce::DirectoryEntry::isHidden
bool isHidden() const
True if the item is hidden, false otherwise.
Definition: juce_RangedDirectoryIterator.h:54
juce::RangedDirectoryIterator::entry
DirectoryEntry entry
Definition: juce_RangedDirectoryIterator.h:173
juce::RangedDirectoryIterator::RangedDirectoryIterator
RangedDirectoryIterator()=default
The default-constructed iterator acts as the 'end' sentinel.