Browse Source

Made DirectoryIterator capable of parsing multiple wildcard patterns.

tags/2021-05-28
jules 12 years ago
parent
commit
4b6a094d13
3 changed files with 32 additions and 13 deletions
  1. +1
    -1
      extras/Introjucer/Source/ComponentEditor/ui/jucer_JucerDocumentEditor.cpp
  2. +28
    -11
      modules/juce_core/files/juce_DirectoryIterator.cpp
  3. +3
    -1
      modules/juce_core/files/juce_DirectoryIterator.h

+ 1
- 1
extras/Introjucer/Source/ComponentEditor/ui/jucer_JucerDocumentEditor.cpp View File

@@ -338,7 +338,7 @@ JucerDocumentEditor::JucerDocumentEditor (JucerDocument* const doc)
updateTabs(); updateTabs();
tabbedComponent.setCurrentTabIndex (0);
tabbedComponent.setCurrentTabIndex (1);
document->addChangeListener (this); document->addChangeListener (this);


+ 28
- 11
modules/juce_core/files/juce_DirectoryIterator.cpp View File

@@ -23,22 +23,39 @@
============================================================================== ==============================================================================
*/ */
DirectoryIterator::DirectoryIterator (const File& directory,
bool isRecursive_,
const String& wildCard_,
const int whatToLookFor_)
: fileFinder (directory, isRecursive_ ? "*" : wildCard_),
wildCard (wildCard_),
static StringArray parseWildcards (const String& pattern)
{
StringArray s;
s.addTokens (pattern, ";,", "\"'");
s.trim();
s.removeEmptyStrings();
return s;
}
static bool fileMatches (const StringArray& wildCards, const String& filename)
{
for (int i = 0; i < wildCards.size(); ++i)
if (filename.matchesWildcard (wildCards[i], ! File::areFileNamesCaseSensitive()))
return true;
return false;
}
DirectoryIterator::DirectoryIterator (const File& directory, bool recursive,
const String& pattern, const int type)
: wildCards (parseWildcards (pattern)),
fileFinder (directory, (recursive || wildCards.size() > 1) ? "*" : pattern),
wildCard (pattern),
path (File::addTrailingSeparator (directory.getFullPathName())), path (File::addTrailingSeparator (directory.getFullPathName())),
index (-1), index (-1),
totalNumFiles (-1), totalNumFiles (-1),
whatToLookFor (whatToLookFor_),
isRecursive (isRecursive_),
whatToLookFor (type),
isRecursive (recursive),
hasBeenAdvanced (false) hasBeenAdvanced (false)
{ {
// you have to specify the type of files you're looking for! // you have to specify the type of files you're looking for!
jassert ((whatToLookFor_ & (File::findFiles | File::findDirectories)) != 0);
jassert (whatToLookFor_ > 0 && whatToLookFor_ <= 7);
jassert ((type & (File::findFiles | File::findDirectories)) != 0);
jassert (type > 0 && type <= 7);
} }
DirectoryIterator::~DirectoryIterator() DirectoryIterator::~DirectoryIterator()
@@ -91,7 +108,7 @@ bool DirectoryIterator::next (bool* const isDirResult, bool* const isHiddenResul
// if recursive, we're not relying on the OS iterator to do the wildcard match, so do it now.. // if recursive, we're not relying on the OS iterator to do the wildcard match, so do it now..
if (matches && isRecursive) if (matches && isRecursive)
matches = filename.matchesWildcard (wildCard, ! File::areFileNamesCaseSensitive());
matches = fileMatches (wildCards, filename);
if (matches && (whatToLookFor & File::ignoreHiddenFiles) != 0) if (matches && (whatToLookFor & File::ignoreHiddenFiles) != 0)
matches = ! isHidden; matches = ! isHidden;


+ 3
- 1
modules/juce_core/files/juce_DirectoryIterator.h View File

@@ -64,7 +64,8 @@ public:
@param directory the directory to search in @param directory the directory to search in
@param isRecursive whether all the subdirectories should also be searched @param isRecursive whether all the subdirectories should also be searched
@param wildCard the file pattern to match
@param wildCard the file pattern to match. This may contain multiple patterns
separated by a semi-colon or comma, e.g. "*.jpg;*.png"
@param whatToLookFor a value from the File::TypesOfFileToFind enum, specifying @param whatToLookFor a value from the File::TypesOfFileToFind enum, specifying
whether to look for files, directories, or both. whether to look for files, directories, or both.
*/ */
@@ -138,6 +139,7 @@ private:
}; };
friend class ScopedPointer<NativeIterator::Pimpl>; friend class ScopedPointer<NativeIterator::Pimpl>;
StringArray wildCards;
NativeIterator fileFinder; NativeIterator fileFinder;
String wildCard, path; String wildCard, path;
int index; int index;


Loading…
Cancel
Save