LMMS
Loading...
Searching...
No Matches
juce::DirectoryIterator Class Referencefinal

#include <juce_DirectoryIterator.h>

Classes

struct  NativeIterator

Public Member Functions

 DirectoryIterator (const File &directory, bool recursive, const String &pattern="*", int type=File::findFiles, File::FollowSymlinks follow=File::FollowSymlinks::yes)
bool next ()
bool next (bool *isDirectory, bool *isHidden, int64 *fileSize, Time *modTime, Time *creationTime, bool *isReadOnly)
const FilegetFile () const
float getEstimatedProgress () const

Private Types

using KnownPaths = std::set<File>

Private Member Functions

 DirectoryIterator (const File &directory, bool recursive, const String &pattern, int type, File::FollowSymlinks follow, KnownPaths *seenPaths)

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 = -1
int totalNumFiles = -1
const int whatToLookFor
const bool isRecursive
bool hasBeenAdvanced = false
std::unique_ptr< DirectoryIteratorsubIterator
File currentFile
File::FollowSymlinks followSymlinks = File::FollowSymlinks::yes
KnownPathsknownPaths = nullptr
std::unique_ptr< KnownPathsheapKnownPaths

Detailed Description

This class is now deprecated in favour of RangedDirectoryIterator.

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.

The iterator keeps track of directories that it has previously traversed, and will skip any previously-seen directories in the case of cycles caused by symbolic links. It is also possible to avoid following symbolic links altogether.

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.

Please note that the order in which files are returned is completely undefined! They'll arrive in whatever order the underlying OS calls provide them, which will depend on the filesystem and other factors. If you need a sorted list, you'll need to manually sort them using your preferred comparator after collecting the list.

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

@tags{Core}

See also
RangedDirectoryIterator

Member Typedef Documentation

◆ KnownPaths

using juce::DirectoryIterator::KnownPaths = std::set<File>
private

Constructor & Destructor Documentation

◆ DirectoryIterator() [1/2]

juce::DirectoryIterator::DirectoryIterator ( const File & directory,
bool recursive,
const String & pattern = "*",
int type = File::findFiles,
File::FollowSymlinks follow = File::FollowSymlinks::yes )
inline

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 recursive, const String &pattern="*", int type=File::findFiles, File::FollowSymlinks follow=File::FollowSymlinks::yes)
Definition juce_DirectoryIterator.h:77
Definition juce_File.h:45
See also
RangedDirectoryIterator

◆ DirectoryIterator() [2/2]

juce::DirectoryIterator::DirectoryIterator ( const File & directory,
bool recursive,
const String & pattern,
int type,
File::FollowSymlinks follow,
KnownPaths * seenPaths )
inlineprivate

Member Function Documentation

◆ fileMatches()

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

◆ getEstimatedProgress()

float juce::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()

JUCE_END_IGNORE_WARNINGS_GCC_LIKE JUCE_END_IGNORE_WARNINGS_MSVC const File & juce::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 juce::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 juce::DirectoryIterator::next ( bool * isDirectory,
bool * isHidden,
int64 * fileSize,
Time * modTime,
Time * creationTime,
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 juce::DirectoryIterator::parseWildcards ( const String & pattern)
staticprivate

Member Data Documentation

◆ currentFile

File juce::DirectoryIterator::currentFile
private

◆ fileFinder

NativeIterator juce::DirectoryIterator::fileFinder
private

◆ followSymlinks

File::FollowSymlinks juce::DirectoryIterator::followSymlinks = File::FollowSymlinks::yes
private

◆ hasBeenAdvanced

bool juce::DirectoryIterator::hasBeenAdvanced = false
private

◆ heapKnownPaths

std::unique_ptr<KnownPaths> juce::DirectoryIterator::heapKnownPaths
private

◆ index

int juce::DirectoryIterator::index = -1
private

◆ isRecursive

const bool juce::DirectoryIterator::isRecursive
private

◆ knownPaths

KnownPaths* juce::DirectoryIterator::knownPaths = nullptr
private

◆ path

String juce::DirectoryIterator::path
private

◆ subIterator

std::unique_ptr<DirectoryIterator> juce::DirectoryIterator::subIterator
private

◆ totalNumFiles

int juce::DirectoryIterator::totalNumFiles = -1
mutableprivate

◆ whatToLookFor

const int juce::DirectoryIterator::whatToLookFor
private

◆ wildCard

String juce::DirectoryIterator::wildCard
private

◆ wildCards

StringArray juce::DirectoryIterator::wildCards
private

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