OpenShot Audio Library | OpenShotAudio 0.4.0
Loading...
Searching...
No Matches
juce_DirectoryIterator.h
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26#ifndef DOXYGEN
27
28//==============================================================================
56{
57public:
58 //==============================================================================
76 [[deprecated ("This class is now deprecated in favour of RangedDirectoryIterator.")]]
77 DirectoryIterator (const File& directory,
78 bool recursive,
79 const String& pattern = "*",
80 int type = File::findFiles,
81 File::FollowSymlinks follow = File::FollowSymlinks::yes)
82 : DirectoryIterator (directory, recursive, pattern, type, follow, nullptr)
83 {
84 }
85
91 bool next();
92
105 bool next (bool* isDirectory,
106 bool* isHidden,
107 int64* fileSize,
108 Time* modTime,
109 Time* creationTime,
110 bool* isReadOnly);
111
116 const File& getFile() const;
117
123 float getEstimatedProgress() const;
124
125private:
126 using KnownPaths = std::set<File>;
127
128 DirectoryIterator (const File& directory,
129 bool recursive,
130 const String& pattern,
131 int type,
133 KnownPaths* seenPaths)
134 : wildCards (parseWildcards (pattern)),
135 fileFinder (directory, (recursive || wildCards.size() > 1) ? "*" : pattern),
136 wildCard (pattern),
137 path (File::addTrailingSeparator (directory.getFullPathName())),
138 whatToLookFor (type),
139 isRecursive (recursive),
140 followSymlinks (follow),
141 knownPaths (seenPaths)
142 {
143 // you have to specify the type of files you're looking for!
144 jassert ((whatToLookFor & (File::findFiles | File::findDirectories)) != 0);
145 jassert (whatToLookFor > 0 && whatToLookFor <= 7);
146
147 if (followSymlinks == File::FollowSymlinks::noCycles)
148 {
149 if (knownPaths == nullptr)
150 {
151 heapKnownPaths = std::make_unique<KnownPaths>();
152 knownPaths = heapKnownPaths.get();
153 }
154
155 knownPaths->insert (directory);
156 }
157 }
158
159 //==============================================================================
160 struct NativeIterator
161 {
162 NativeIterator (const File& directory, const String& wildCard);
163 ~NativeIterator();
164
165 bool next (String& filenameFound,
166 bool* isDirectory, bool* isHidden, int64* fileSize,
167 Time* modTime, Time* creationTime, bool* isReadOnly);
168
169 class Pimpl;
170 std::unique_ptr<Pimpl> pimpl;
171
172 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NativeIterator)
173 };
174
175 StringArray wildCards;
176 NativeIterator fileFinder;
177 String wildCard, path;
178 int index = -1;
179 mutable int totalNumFiles = -1;
180 const int whatToLookFor;
181 const bool isRecursive;
182 bool hasBeenAdvanced = false;
183 std::unique_ptr<DirectoryIterator> subIterator;
184 File currentFile;
185 File::FollowSymlinks followSymlinks = File::FollowSymlinks::yes;
186 KnownPaths* knownPaths = nullptr;
187 std::unique_ptr<KnownPaths> heapKnownPaths;
188
189 static StringArray parseWildcards (const String& pattern);
190 static bool fileMatches (const StringArray& wildCards, const String& filename);
191
192 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DirectoryIterator)
193};
194
195#endif
196
197} // namespace juce
DirectoryIterator(const File &directory, bool recursive, const String &pattern="*", int type=File::findFiles, File::FollowSymlinks follow=File::FollowSymlinks::yes)