The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
4.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-9 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_DIRECTORYITERATOR_JUCEHEADER__
  19. #define __JUCE_DIRECTORYITERATOR_JUCEHEADER__
  20. #include "juce_File.h"
  21. #include "../../containers/juce_ScopedPointer.h"
  22. //==============================================================================
  23. /**
  24. Searches through a the files in a directory, returning each file that is found.
  25. A DirectoryIterator will search through a directory and its subdirectories using
  26. a wildcard filepattern match.
  27. If you may be finding a large number of files, this is better than
  28. using File::findChildFiles() because it doesn't block while it finds them
  29. all, and this is more memory-efficient.
  30. It can also guess how far it's got using a wildly inaccurate algorithm.
  31. */
  32. class JUCE_API DirectoryIterator
  33. {
  34. public:
  35. //==============================================================================
  36. /** Creates a DirectoryIterator for a given directory.
  37. After creating one of these, call its next() method to get the
  38. first file - e.g. @code
  39. DirectoryIterator iter (File ("/animals/mooses"), true, "*.moose");
  40. while (iter.next())
  41. {
  42. File theFileItFound (iter.getFile());
  43. ... etc
  44. }
  45. @endcode
  46. @param directory the directory to search in
  47. @param isRecursive whether all the subdirectories should also be searched
  48. @param wildCard the file pattern to match
  49. @param whatToLookFor a value from the File::TypesOfFileToFind enum, specifying
  50. whether to look for files, directories, or both.
  51. */
  52. DirectoryIterator (const File& directory,
  53. bool isRecursive,
  54. const String& wildCard = JUCE_T("*"),
  55. int whatToLookFor = File::findFiles);
  56. /** Destructor. */
  57. ~DirectoryIterator();
  58. /** Call this to move the iterator along to the next file.
  59. @returns true if a file was found (you can then use getFile() to see what it was) - or
  60. false if there are no more matching files.
  61. */
  62. bool next();
  63. /** Returns the file that the iterator is currently pointing at.
  64. The result of this call is only valid after a call to next() has returned true.
  65. */
  66. const File getFile() const;
  67. /** Returns a guess of how far through the search the iterator has got.
  68. @returns a value 0.0 to 1.0 to show the progress, although this won't be
  69. very accurate.
  70. */
  71. float getEstimatedProgress() const;
  72. //==============================================================================
  73. juce_UseDebuggingNewOperator
  74. private:
  75. Array <File> filesFound;
  76. Array <File> dirsFound;
  77. String wildCard;
  78. int index;
  79. const int whatToLookFor;
  80. ScopedPointer <DirectoryIterator> subIterator;
  81. DirectoryIterator (const DirectoryIterator&);
  82. DirectoryIterator& operator= (const DirectoryIterator&);
  83. };
  84. #endif // __JUCE_DIRECTORYITERATOR_JUCEHEADER__