LMMS
Loading...
Searching...
No Matches
water::DirectoryIterator Class Reference

#include <DirectoryIterator.h>

Classes

class  NativeIterator

Public Member Functions

 DirectoryIterator (const File &directory, bool isRecursive, const String &wildCard="*", int whatToLookFor=File::findFiles)
 ~DirectoryIterator ()
bool next ()
bool next (bool *isDirectory, int64 *fileSize, bool *isReadOnly)
const FilegetFile () const
float getEstimatedProgress () const

Static Private Member Functions

static StringArray parseWildcards (const String &pattern)
static bool fileMatches (const StringArray &wildCards, const String &filename)

Private Attributes

StringArray wildCards
NativeIterator fileFinder
String wildCard
String path
int index
int totalNumFiles
const int whatToLookFor
const bool isRecursive
bool hasBeenAdvanced
CarlaScopedPointer< DirectoryIteratorsubIterator
File currentFile

Detailed Description

Searches through the files in a directory, returning each file that is found.

A DirectoryIterator will search through a directory and its subdirectories using a wildcard filepattern match.

If you may be scanning a large number of files, it's usually smarter to use this class than File::findChildFiles() because it allows you to stop at any time, rather than having to wait for the entire scan to finish before getting the results.

It also provides an estimate of its progress, using a (highly inaccurate!) algorithm.

Constructor & Destructor Documentation

◆ DirectoryIterator()

water::DirectoryIterator::DirectoryIterator ( const File & directory,
bool isRecursive,
const String & wildCard = "*",
int whatToLookFor = File::findFiles )

Creates a DirectoryIterator for a given directory.

After creating one of these, call its next() method to get the first file - e.g.

DirectoryIterator iter (File ("/animals/mooses"), true, "*.moose");
while (iter.next())
{
File theFileItFound (iter.getFile());
... etc
}
DirectoryIterator(const File &directory, bool isRecursive, const String &wildCard="*", int whatToLookFor=File::findFiles)
Definition DirectoryIterator.cpp:31
Definition File.h:50
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.

◆ ~DirectoryIterator()

water::DirectoryIterator::~DirectoryIterator ( )

Destructor.

Member Function Documentation

◆ fileMatches()

bool water::DirectoryIterator::fileMatches ( const StringArray & wildCards,
const String & filename )
staticprivate

◆ getEstimatedProgress()

float water::DirectoryIterator::getEstimatedProgress ( ) const

Returns a guess of how far through the search the iterator has got.

Returns
a value 0.0 to 1.0 to show the progress, although this won't be very accurate.

◆ getFile()

const File & water::DirectoryIterator::getFile ( ) const

Returns the file that the iterator is currently pointing at.

The result of this call is only valid after a call to next() has returned true.

◆ next() [1/2]

bool water::DirectoryIterator::next ( )

Moves the iterator along to the next file.

Returns
true if a file was found (you can then use getFile() to see what it was) - or false if there are no more matching files.

◆ next() [2/2]

bool water::DirectoryIterator::next ( bool * isDirectory,
int64 * fileSize,
bool * isReadOnly )

Moves the iterator along to the next file, and returns various properties of that file.

If you need to find out details about the file, it's more efficient to call this method than to call the normal next() method and then find out the details afterwards.

All the parameters are optional, so pass null pointers for any items that you're not interested in.

Returns
true if a file was found (you can then use getFile() to see what it was) - or false if there are no more matching files. If it returns false, then none of the parameters will be filled-in.

◆ parseWildcards()

StringArray water::DirectoryIterator::parseWildcards ( const String & pattern)
staticprivate

Member Data Documentation

◆ currentFile

File water::DirectoryIterator::currentFile
private

◆ fileFinder

NativeIterator water::DirectoryIterator::fileFinder
private

◆ hasBeenAdvanced

bool water::DirectoryIterator::hasBeenAdvanced
private

◆ index

int water::DirectoryIterator::index
private

◆ isRecursive

const bool water::DirectoryIterator::isRecursive
private

◆ path

String water::DirectoryIterator::path
private

◆ subIterator

CarlaScopedPointer<DirectoryIterator> water::DirectoryIterator::subIterator
private

◆ totalNumFiles

int water::DirectoryIterator::totalNumFiles
mutableprivate

◆ whatToLookFor

const int water::DirectoryIterator::whatToLookFor
private

◆ wildCard

String water::DirectoryIterator::wildCard
private

◆ wildCards

StringArray water::DirectoryIterator::wildCards
private

The documentation for this class was generated from the following files: