OpenShot Library | OpenShotAudio  0.2.1
juce_DirectoryIterator.h
1 
2 /** @weakgroup juce_core-files
3  * @{
4  */
5 /*
6  ==============================================================================
7 
8  This file is part of the JUCE library.
9  Copyright (c) 2017 - ROLI Ltd.
10 
11  JUCE is an open source library subject to commercial or open-source
12  licensing.
13 
14  The code included in this file is provided under the terms of the ISC license
15  http://www.isc.org/downloads/software-support-policy/isc-license. Permission
16  To use, copy, modify, and/or distribute this software for any purpose with or
17  without fee is hereby granted provided that the above copyright notice and
18  this permission notice appear in all copies.
19 
20  JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21  EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22  DISCLAIMED.
23 
24  ==============================================================================
25 */
26 
27 namespace juce
28 {
29 
30 //==============================================================================
31 /**
32  Searches through the files in a directory, returning each file that is found.
33 
34  A DirectoryIterator will search through a directory and its subdirectories using
35  a wildcard filepattern match.
36 
37  If you may be scanning a large number of files, it's usually smarter to use this
38  class than File::findChildFiles() because it allows you to stop at any time, rather
39  than having to wait for the entire scan to finish before getting the results.
40 
41  Please note that the order in which files are returned is completely undefined!
42  They'll arrive in whatever order the underlying OS calls provide them, which will
43  depend on the filesystem and other factors. If you need a sorted list, you'll need
44  to manually sort them using your preferred comparator after collecting the list.
45 
46  It also provides an estimate of its progress, using a (highly inaccurate!) algorithm.
47 
48  @tags{Core}
49 */
51 {
52 public:
53  //==============================================================================
54  /** Creates a DirectoryIterator for a given directory.
55 
56  After creating one of these, call its next() method to get the
57  first file - e.g. @code
58 
59  DirectoryIterator iter (File ("/animals/mooses"), true, "*.moose");
60 
61  while (iter.next())
62  {
63  File theFileItFound (iter.getFile());
64 
65  ... etc
66  }
67  @endcode
68 
69  @param directory the directory to search in
70  @param isRecursive whether all the subdirectories should also be searched
71  @param wildCard the file pattern to match. This may contain multiple patterns
72  separated by a semi-colon or comma, e.g. "*.jpg;*.png"
73  @param whatToLookFor a value from the File::TypesOfFileToFind enum, specifying
74  whether to look for files, directories, or both.
75  */
76  DirectoryIterator (const File& directory,
77  bool isRecursive,
78  const String& wildCard = "*",
79  int whatToLookFor = File::findFiles);
80 
81  /** Destructor. */
83 
84  /** Moves the iterator along to the next file.
85 
86  @returns true if a file was found (you can then use getFile() to see what it was) - or
87  false if there are no more matching files.
88  */
89  bool next();
90 
91  /** Moves the iterator along to the next file, and returns various properties of that file.
92 
93  If you need to find out details about the file, it's more efficient to call this method than
94  to call the normal next() method and then find out the details afterwards.
95 
96  All the parameters are optional, so pass null pointers for any items that you're not
97  interested in.
98 
99  @returns true if a file was found (you can then use getFile() to see what it was) - or
100  false if there are no more matching files. If it returns false, then none of the
101  parameters will be filled-in.
102  */
103  bool next (bool* isDirectory,
104  bool* isHidden,
105  int64* fileSize,
106  Time* modTime,
107  Time* creationTime,
108  bool* isReadOnly);
109 
110  /** Returns the file that the iterator is currently pointing at.
111 
112  The result of this call is only valid after a call to next() has returned true.
113  */
114  const File& getFile() const;
115 
116  /** Returns a guess of how far through the search the iterator has got.
117 
118  @returns a value 0.0 to 1.0 to show the progress, although this won't be
119  very accurate.
120  */
121  float getEstimatedProgress() const;
122 
123 private:
124  //==============================================================================
125  struct NativeIterator
126  {
127  NativeIterator (const File& directory, const String& wildCard);
128  ~NativeIterator();
129 
130  bool next (String& filenameFound,
131  bool* isDirectory, bool* isHidden, int64* fileSize,
132  Time* modTime, Time* creationTime, bool* isReadOnly);
133 
134  class Pimpl;
135  std::unique_ptr<Pimpl> pimpl;
136 
137  JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NativeIterator)
138  };
139 
140  StringArray wildCards;
141  NativeIterator fileFinder;
142  String wildCard, path;
143  int index = -1;
144  mutable int totalNumFiles = -1;
145  const int whatToLookFor;
146  const bool isRecursive;
147  bool hasBeenAdvanced = false;
148  std::unique_ptr<DirectoryIterator> subIterator;
149  File currentFile;
150 
151  static StringArray parseWildcards (const String& pattern);
152  static bool fileMatches (const StringArray& wildCards, const String& filename);
153 
154  JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DirectoryIterator)
155 };
156 
157 } // namespace juce
158 
159 /** @}*/
#define JUCE_API
This macro is added to all JUCE public class declarations.
Searches through the files in a directory, returning each file that is found.
A special array for holding a list of strings.
The JUCE String class!
Definition: juce_String.h:42
Use this flag to indicate that you want to find files.
Definition: juce_File.h:554
Represents a local file or directory.
Definition: juce_File.h:44
Holds an absolute date and time.
Definition: juce_Time.h:40