LMMS
Loading...
Searching...
No Matches
juce_DirectoryIterator.cpp
Go to the documentation of this file.
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
27{
29 s.addTokens (pattern, ";,", "\"'");
30 s.trim();
31 s.removeEmptyStrings();
32 return s;
33}
34
36{
37 for (auto& w : wildcards)
38 if (filename.matchesWildcard (w, ! File::areFileNamesCaseSensitive()))
39 return true;
40
41 return false;
42}
43
45{
46 return next (nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
47}
48
49JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wdeprecated-declarations")
51
52bool DirectoryIterator::next (bool* isDirResult, bool* isHiddenResult, int64* fileSize,
53 Time* modTime, Time* creationTime, bool* isReadOnly)
54{
55 for (;;)
56 {
57 hasBeenAdvanced = true;
58
59 if (subIterator != nullptr)
60 {
61 if (subIterator->next (isDirResult, isHiddenResult, fileSize, modTime, creationTime, isReadOnly))
62 return true;
63
64 subIterator.reset();
65 }
66
68 bool isDirectory, isHidden = false, shouldContinue = false;
69
70 while (fileFinder.next (filename, &isDirectory,
71 (isHiddenResult != nullptr || (whatToLookFor & File::ignoreHiddenFiles) != 0) ? &isHidden : nullptr,
72 fileSize, modTime, creationTime, isReadOnly))
73 {
74 ++index;
75
76 if (! filename.containsOnly ("."))
77 {
78 const auto fullPath = File::createFileWithoutCheckingPath (path + filename);
79 bool matches = false;
80
81 if (isDirectory)
82 {
83 const auto mayRecurseIntoPossibleHiddenDir = [this, &isHidden]
84 {
85 return (whatToLookFor & File::ignoreHiddenFiles) == 0 || ! isHidden;
86 };
87
88 const auto mayRecurseIntoPossibleSymlink = [this, &fullPath]
89 {
91 || ! fullPath.isSymbolicLink()
93 && knownPaths->find (fullPath.getLinkedTarget()) == knownPaths->end());
94 };
95
96 if (isRecursive && mayRecurseIntoPossibleHiddenDir() && mayRecurseIntoPossibleSymlink())
98
99 matches = (whatToLookFor & File::findDirectories) != 0;
100 }
101 else
102 {
103 matches = (whatToLookFor & File::findFiles) != 0;
104 }
105
106 // if we're not relying on the OS iterator to do the wildcard match, do it now..
107 if (matches && (isRecursive || wildCards.size() > 1))
108 matches = fileMatches (wildCards, filename);
109
110 if (matches && (whatToLookFor & File::ignoreHiddenFiles) != 0)
111 matches = ! isHidden;
112
113 if (matches)
114 {
115 currentFile = fullPath;
116 if (isHiddenResult != nullptr) *isHiddenResult = isHidden;
117 if (isDirResult != nullptr) *isDirResult = isDirectory;
118
119 return true;
120 }
121
122 if (subIterator != nullptr)
123 {
124 shouldContinue = true;
125 break;
126 }
127 }
128 }
129
130 if (! shouldContinue)
131 return false;
132 }
133}
134
137
139{
140 if (subIterator != nullptr && subIterator->hasBeenAdvanced)
141 return subIterator->getFile();
142
143 // You need to call DirectoryIterator::next() before asking it for the file that it found!
145
146 return currentFile;
147}
148
150{
151 if (totalNumFiles < 0)
153
154 if (totalNumFiles <= 0)
155 return 0.0f;
156
157 auto detailedIndex = (subIterator != nullptr) ? (float) index + subIterator->getEstimatedProgress()
158 : (float) index;
159
160 return jlimit (0.0f, 1.0f, detailedIndex / (float) totalNumFiles);
161}
162
163} // namespace juce
static File createFileWithoutCheckingPath(const String &absolutePath) noexcept
Definition File.cpp:65
NativeIterator fileFinder
Definition juce_DirectoryIterator.h:176
const int whatToLookFor
Definition juce_DirectoryIterator.h:180
StringArray wildCards
Definition juce_DirectoryIterator.h:175
File::FollowSymlinks followSymlinks
Definition juce_DirectoryIterator.h:185
const File & getFile() const
Definition juce_DirectoryIterator.cpp:138
static bool fileMatches(const StringArray &wildCards, const String &filename)
Definition juce_DirectoryIterator.cpp:35
String wildCard
Definition juce_DirectoryIterator.h:177
DirectoryIterator(const File &directory, bool recursive, const String &pattern="*", int type=File::findFiles, File::FollowSymlinks follow=File::FollowSymlinks::yes)
Definition juce_DirectoryIterator.h:77
KnownPaths * knownPaths
Definition juce_DirectoryIterator.h:186
static StringArray parseWildcards(const String &pattern)
Definition juce_DirectoryIterator.cpp:26
const bool isRecursive
Definition juce_DirectoryIterator.h:181
String path
Definition juce_DirectoryIterator.h:177
int index
Definition juce_DirectoryIterator.h:178
bool hasBeenAdvanced
Definition juce_DirectoryIterator.h:182
File currentFile
Definition juce_DirectoryIterator.h:184
bool next()
Definition juce_DirectoryIterator.cpp:44
int totalNumFiles
Definition juce_DirectoryIterator.h:179
std::unique_ptr< DirectoryIterator > subIterator
Definition juce_DirectoryIterator.h:183
float getEstimatedProgress() const
Definition juce_DirectoryIterator.cpp:149
Definition juce_File.h:45
int getNumberOfChildFiles(int whatToLookFor, const String &wildCardPattern="*") const
Definition juce_File.cpp:584
@ ignoreHiddenFiles
Definition juce_File.h:562
@ findDirectories
Definition juce_File.h:559
@ findFilesAndDirectories
Definition juce_File.h:561
@ findFiles
Definition juce_File.h:560
static bool areFileNamesCaseSensitive()
Definition juce_File.cpp:236
@ yes
Definition juce_File.h:579
@ noCycles
Definition juce_File.h:573
Definition juce_StringArray.h:35
Definition juce_String.h:53
Definition juce_Time.h:37
UINT_D64 w
Definition inflate.c:942
unsigned s
Definition inflate.c:1555
static char filename[]
Definition features.c:5
#define JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE(...)
Definition juce_CompilerWarnings.h:181
#define JUCE_END_IGNORE_WARNINGS_GCC_LIKE
Definition juce_CompilerWarnings.h:182
#define JUCE_BEGIN_IGNORE_WARNINGS_MSVC(warnings)
Definition juce_CompilerWarnings.h:198
#define JUCE_END_IGNORE_WARNINGS_MSVC
Definition juce_CompilerWarnings.h:199
#define jassert(expression)
Definition carla_juce.cpp:31
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
Definition juce_MathsFunctions.h:262
long long int64
Definition juce_MathsFunctions.h:54
int * pattern
Definition match.c:126