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);
53 bool DirectoryIterator::fileMatches (
const StringArray& wildcards,
const String& filename)
55 for (
auto& w : wildcards)
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))
97 if (isRecursive && ((whatToLookFor & File::ignoreHiddenFiles) == 0 || ! isHidden))
99 true, wildCard, whatToLookFor));
109 if (matches && (isRecursive || wildCards.
size() > 1))
110 matches = fileMatches (wildCards, filename);
112 if (matches && (whatToLookFor & File::ignoreHiddenFiles) != 0)
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);
bool containsOnly(StringRef charactersItMightContain) const noexcept
Looks for a set of characters in the string.
Searches through the files in a directory, returning each file that is found.
~DirectoryIterator()
Destructor.
static File createFileWithoutCheckingPath(const String &absolutePath) noexcept
Creates a file that simply contains this string, without doing the sanity-checking that the normal co...
void removeEmptyStrings(bool removeWhitespaceStrings=true)
Removes empty strings from the array.
A special array for holding a list of strings.
Use this flag to indicate that you want to find both files and directories.
Add this flag to avoid returning any hidden files in the results.
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.
Use this flag to indicate that you want to find files.
Use this flag to indicate that you want to find directories.
Represents a local file or directory.
DirectoryIterator(const File &directory, bool isRecursive, const String &wildCard="*", int whatToLookFor=File::findFiles)
Creates a DirectoryIterator for a given directory.
bool matchesWildcard(StringRef wildcard, bool ignoreCase) const noexcept
Returns true if the string matches this simple wildcard expression.
static bool areFileNamesCaseSensitive()
Indicates whether filenames are case-sensitive on the current operating system.
int size() const noexcept
Returns the number of strings in the array.
float getEstimatedProgress() const
Returns a guess of how far through the search the iterator has got.
Holds an absolute date and time.
bool next()
Moves the iterator along to the next file.
int getNumberOfChildFiles(int whatToLookFor, const String &wildCardPattern="*") const
Searches inside a directory and counts how many files match a wildcard pattern.
const File & getFile() const
Returns the file that the iterator is currently pointing at.