27 const String& pattern,
int type)
28 : wildCards (parseWildcards (pattern)),
29 fileFinder (directory, (recursive || wildCards.size() > 1) ?
"*" : pattern),
31 path (
File::addTrailingSeparator (directory.getFullPathName())),
33 isRecursive (recursive)
37 jassert (type > 0 && type <= 7);
53bool DirectoryIterator::fileMatches (
const StringArray& wildcards,
const String& filename)
55 for (
auto& w : wildcards)
56 if (filename.matchesWildcard (w, ! File::areFileNamesCaseSensitive()))
64 return next (
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr);
68 Time* modTime,
Time* creationTime,
bool* isReadOnly)
72 hasBeenAdvanced =
true;
74 if (subIterator !=
nullptr)
76 if (subIterator->next (isDirResult, isHiddenResult, fileSize, modTime, creationTime, isReadOnly))
83 bool isDirectory, isHidden =
false, shouldContinue =
false;
85 while (fileFinder.next (filename, &isDirectory,
87 fileSize, modTime, creationTime, isReadOnly))
99 true, wildCard, whatToLookFor));
109 if (matches && (isRecursive || wildCards.
size() > 1))
110 matches = fileMatches (wildCards, filename);
113 matches = ! isHidden;
118 if (isHiddenResult !=
nullptr) *isHiddenResult = isHidden;
119 if (isDirResult !=
nullptr) *isDirResult = isDirectory;
124 if (subIterator !=
nullptr)
126 shouldContinue =
true;
132 if (! shouldContinue)
139 if (subIterator !=
nullptr && subIterator->hasBeenAdvanced)
140 return subIterator->getFile();
143 jassert (hasBeenAdvanced);
150 if (totalNumFiles < 0)
153 if (totalNumFiles <= 0)
156 auto detailedIndex = (subIterator !=
nullptr) ? index + subIterator->getEstimatedProgress()
159 return jlimit (0.0f, 1.0f, detailedIndex / totalNumFiles);
Searches through the files in a directory, returning each file that is found.
const File & getFile() const
Returns the file that the iterator is currently pointing at.
bool next()
Moves the iterator along to the next file.
float getEstimatedProgress() const
Returns a guess of how far through the search the iterator has got.
DirectoryIterator(const File &directory, bool isRecursive, const String &wildCard="*", int whatToLookFor=File::findFiles)
Creates a DirectoryIterator for a given directory.
~DirectoryIterator()
Destructor.
Represents a local file or directory.
int getNumberOfChildFiles(int whatToLookFor, const String &wildCardPattern="*") const
Searches inside a directory and counts how many files match a wildcard pattern.
@ ignoreHiddenFiles
Add this flag to avoid returning any hidden files in the results.
@ findDirectories
Use this flag to indicate that you want to find directories.
@ findFilesAndDirectories
Use this flag to indicate that you want to find both files and directories.
@ findFiles
Use this flag to indicate that you want to find files.
static File createFileWithoutCheckingPath(const String &absolutePath) noexcept
Creates a file that simply contains this string, without doing the sanity-checking that the normal co...
A special array for holding a list of strings.
void removeEmptyStrings(bool removeWhitespaceStrings=true)
Removes empty strings from the array.
int size() const noexcept
Returns the number of strings in the array.
void trim()
Deletes any whitespace characters from the starts and ends of all the strings.
int addTokens(StringRef stringToTokenise, bool preserveQuotedStrings)
Breaks up a string into tokens and adds them to this array.
bool containsOnly(StringRef charactersItMightContain) const noexcept
Looks for a set of characters in the string.
Holds an absolute date and time.