Loading...
Searching...
No Matches
juce_DirectoryIterator.h
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
To use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
#ifndef DOXYGEN
//==============================================================================
class JUCE_API DirectoryIterator final
{
public:
//==============================================================================
[[deprecated ("This class is now deprecated in favour of RangedDirectoryIterator.")]]
DirectoryIterator (const File& directory,
bool recursive,
const String& pattern = "*",
int type = File::findFiles,
File::FollowSymlinks follow = File::FollowSymlinks::yes)
: DirectoryIterator (directory, recursive, pattern, type, follow, nullptr)
{
}
bool next();
bool next (bool* isDirectory,
bool* isHidden,
int64* fileSize,
Time* modTime,
Time* creationTime,
bool* isReadOnly);
const File& getFile() const;
float getEstimatedProgress() const;
private:
using KnownPaths = std::set<File>;
DirectoryIterator (const File& directory,
bool recursive,
const String& pattern,
int type,
File::FollowSymlinks follow,
KnownPaths* seenPaths)
: wildCards (parseWildcards (pattern)),
fileFinder (directory, (recursive || wildCards.size() > 1) ? "*" : pattern),
wildCard (pattern),
path (File::addTrailingSeparator (directory.getFullPathName())),
whatToLookFor (type),
isRecursive (recursive),
followSymlinks (follow),
knownPaths (seenPaths)
{
// you have to specify the type of files you're looking for!
jassert ((whatToLookFor & (File::findFiles | File::findDirectories)) != 0);
jassert (whatToLookFor > 0 && whatToLookFor <= 7);
if (followSymlinks == File::FollowSymlinks::noCycles)
{
if (knownPaths == nullptr)
{
heapKnownPaths = std::make_unique<KnownPaths>();
knownPaths = heapKnownPaths.get();
}
knownPaths->insert (directory);
}
}
//==============================================================================
struct NativeIterator
{
NativeIterator (const File& directory, const String& wildCard);
~NativeIterator();
bool next (String& filenameFound,
bool* isDirectory, bool* isHidden, int64* fileSize,
Time* modTime, Time* creationTime, bool* isReadOnly);
class Pimpl;
std::unique_ptr<Pimpl> pimpl;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NativeIterator)
};
StringArray wildCards;
NativeIterator fileFinder;
String wildCard, path;
int index = -1;
mutable int totalNumFiles = -1;
const int whatToLookFor;
const bool isRecursive;
bool hasBeenAdvanced = false;
std::unique_ptr<DirectoryIterator> subIterator;
File currentFile;
File::FollowSymlinks followSymlinks = File::FollowSymlinks::yes;
KnownPaths* knownPaths = nullptr;
std::unique_ptr<KnownPaths> heapKnownPaths;
static StringArray parseWildcards (const String& pattern);
static bool fileMatches (const StringArray& wildCards, const String& filename);
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DirectoryIterator)
};
#endif
} // namespace juce
juce::DirectoryIterator
Definition juce_DirectoryIterator.h:56
juce::DirectoryIterator::DirectoryIterator
DirectoryIterator(const File &directory, bool recursive, const String &pattern="*", int type=File::findFiles, File::FollowSymlinks follow=File::FollowSymlinks::yes)
Definition juce_DirectoryIterator.h:77
juce::File
Definition juce_File.h:45
juce::File::findDirectories
@ findDirectories
Definition juce_File.h:565
juce::File::findFiles
@ findFiles
Definition juce_File.h:566
juce::File::FollowSymlinks
FollowSymlinks
Definition juce_File.h:572
juce::File::FollowSymlinks::yes
@ yes
Definition juce_File.h:585
juce::File::FollowSymlinks::noCycles
@ noCycles
Definition juce_File.h:579
juce::String
Definition juce_String.h:53
juce::Time
Definition juce_Time.h:37