1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
|
// Copyright (C) 2016 The Qt Company Ltd.
// Copyright (C) 2024 Ahmad Samir <a.samirh78@gmail.com>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
// Qt-Security score:significant reason:default
/*!
\since 6.8
\class QDirListing
\inmodule QtCore
\ingroup io
\brief The QDirListing class provides an STL-style iterator for directory entries.
You can use QDirListing to navigate entries of a directory one at a time.
It is similar to QDir::entryList() and QDir::entryInfoList(), but because
it lists entries one at a time instead of all at once, it scales better
and is more suitable for large directories. It also supports listing
directory contents recursively, and following symbolic links. Unlike
QDir::entryList(), QDirListing does not support sorting.
The QDirListing constructor takes a directory path string as
argument. Here's how to iterate over all entries recursively:
\snippet code/src_corelib_io_qdirlisting.cpp 0
Here's how to find and read all regular files filtered by name, recursively:
\snippet code/src_corelib_io_qdirlisting.cpp 1
Here's how to list only regular files, recursively:
\snippet code/src_corelib_io_qdirlisting.cpp 5
Here's how to list only regular files and symbolic links to regular
files, recursively:
\snippet code/src_corelib_io_qdirlisting.cpp 6
//! [std-input-iterator-tag]
QDirListing::const_iterator models C++20
\l{https://en.cppreference.com/w/cpp/iterator/input_iterator}{std::input_iterator},
that is, it is a move-only, forward-only, single-pass iterator, that
doesn't allow random access.
//! [std-input-iterator-tag]
It can be used in ranged-for loops (or with C++20 range algorithms that don't
require random access iterators). Dereferencing a valid iterator returns
a QDirListing::DirEntry object. The (c)end() sentinel marks the end of
the iteration. Dereferencing an iterator that is equal to \l{sentinel} is
undefined behavior.
QDirListing::DirEntry offers a subset of QFileInfo's API (for example,
fileName(), filePath(), exists()). Internally, DirEntry only constructs
a QFileInfo object if needed, that is, if the info hasn't been already
fetched by other system functions. You can use DirEntry::fileInfo()
to get a QFileInfo. For example:
\snippet code/src_corelib_io_qdirlisting.cpp 3
\snippet code/src_corelib_io_qdirlisting.cpp 4
\sa QDir, QDir::entryList()
*/
/*! \enum QDirListing::IteratorFlag
This enum class describes flags that can be used to configure the behavior
of QDirListing. Values from this enumerator can be bitwise OR'ed together.
\value Default
List all entries, that is, files, directories, symbolic links including broken
symbolic links (where the target doesn't exist) and special (\e other) system
files, see ExcludeOther for details.
Hidden files and directories and the special entries \c{.} and \c{..}
aren't listed by default.
\value ExcludeFiles
Don't list regular files. When combined with ResolveSymlinks, symbolic
links to regular files will be excluded too.
\value ExcludeDirs
Don't list directories. When combined with ResolveSymlinks, symbolic
links to directories will be excluded too.
\omitvalue ExcludeSpecial
\value ExcludeOther [since 6.10]
Don't list file system entries that are \e not directories, regular files,
or symbolic links.
\list
\li On Unix, a special (other) file system entry is a FIFO, socket,
character device, or block device. For more details see the
\l{https://pubs.opengroup.org/onlinepubs/9699919799/functions/mknod.html}{\c mknod}
manual page.
\li On Windows (for historical reasons) \c .lnk files are considered
special (other) file system entries.
\endlist
\value ResolveSymlinks
Filter symbolic links based on the type of the target of the link,
rather than the symbolic link itself. Broken symbolic links (where
the target doesn't exist) are excluded, set IncludeBrokenSymlinks
to include them.
This flag is ignored on operating systems that don't support symbolic links.
\value IncludeBrokenSymlinks [since 6.11]
Lists broken symbolic links, where the target doesn't exist, regardless
of the status of the ResolveSymlinks flag.
This flag is ignored on operating systems that don't support symbolic links.
\value FilesOnly
Only regular files will be listed. When combined with ResolveSymlinks,
symbolic links to files will also be listed.
\value DirsOnly
Only directories will be listed. When combined with ResolveSymlinks,
symbolic links to directories will also be listed.
\value IncludeHidden
List hidden entries. When combined with Recursive, the iteration will
recurse into hidden sub-directories as well.
\value IncludeDotAndDotDot
List the \c {.} and \c{..} special entries.
\value CaseSensitive
The file glob patterns in the name filters passed to the QDirListing
constructor, will be matched case sensitively (for details, see
QDir::setNameFilters()).
\value Recursive
List entries inside all sub-directories as well. When combined with
FollowDirSymlinks, symbolic links to directories will be iterated too.
\value FollowDirSymlinks
When combined with Recursive, symbolic links to directories will be
iterated too. Symbolic link loops (e.g., link => . or link => ..) are
automatically detected and ignored.
\omitvalue NoNameFiltersForDirs
*/
#include "qdirlisting.h"
#include "qdirentryinfo_p.h"
#include "qdir_p.h"
#include "qdiriterator.h"
#include "qabstractfileengine_p.h"
#if QT_CONFIG(regularexpression)
#include <QtCore/qregularexpression.h>
#endif
#include <QtCore/private/qfilesystemiterator_p.h>
#include <QtCore/private/qfilesystementry_p.h>
#include <QtCore/private/qfilesystemmetadata_p.h>
#include <QtCore/private/qfilesystemengine_p.h>
#include <QtCore/private/qfileinfo_p.h>
#include <QtCore/private/qduplicatetracker_p.h>
#include <memory>
#include <vector>
QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
class QDirListingPrivate
{
public:
void init();
void advance();
void beginIterating();
bool entryMatches(QDirEntryInfo &info);
void pushDirectory(QDirEntryInfo &info);
void pushInitialDirectory();
void checkAndPushDirectory(QDirEntryInfo &info);
bool matchesFilters(QDirEntryInfo &data) const;
bool hasIterators() const;
std::unique_ptr<QAbstractFileEngine> engine;
QDirEntryInfo initialEntryInfo;
QStringList nameFilters;
QDirListing::IteratorFlags iteratorFlags;
QDirEntryInfo currentEntryInfo;
#if QT_CONFIG(regularexpression)
QList<QRegularExpression> nameRegExps;
bool regexMatchesName(const QString &fileName) const
{
if (nameRegExps.isEmpty())
return true;
auto hasMatch = [&fileName](const auto &re) { return re.match(fileName).hasMatch(); };
return std::any_of(nameRegExps.cbegin(), nameRegExps.cend(), hasMatch);
}
#endif
using FEngineIteratorPtr = std::unique_ptr<QAbstractFileEngineIterator>;
std::vector<FEngineIteratorPtr> fileEngineIterators;
#ifndef QT_NO_FILESYSTEMITERATOR
using FsIteratorPtr = std::unique_ptr<QFileSystemIterator>;
std::vector<FsIteratorPtr> nativeIterators;
#endif
// Loop protection
QDuplicateTracker<QString> visitedLinks;
};
void QDirListingPrivate::init()
{
if (nameFilters.contains("*"_L1))
nameFilters.clear();
#if QT_CONFIG(regularexpression)
nameRegExps.reserve(nameFilters.size());
const bool isCase = iteratorFlags.testAnyFlags(QDirListing::IteratorFlag::CaseSensitive);
const auto cs = isCase ? Qt::CaseSensitive : Qt::CaseInsensitive;
for (const auto &filter : nameFilters)
nameRegExps.emplace_back(QRegularExpression::fromWildcard(filter, cs));
#endif
engine = QFileSystemEngine::createLegacyEngine(initialEntryInfo.entry,
initialEntryInfo.metaData);
}
/*!
\internal
Resets the iteration state (if any), so that calling begin()/cbegin()
always starts iterating anew.
*/
void QDirListingPrivate::beginIterating()
{
#ifndef QT_NO_FILESYSTEMITERATOR
nativeIterators.clear();
#endif
fileEngineIterators.clear();
visitedLinks.clear();
pushDirectory(initialEntryInfo);
}
void QDirListingPrivate::pushDirectory(QDirEntryInfo &entryInfo)
{
const QString path = [&entryInfo] {
#ifdef Q_OS_WIN
if (entryInfo.isSymLink())
return entryInfo.canonicalFilePath();
#endif
return entryInfo.filePath();
}();
if (iteratorFlags.testAnyFlags(QDirListing::IteratorFlag::FollowDirSymlinks)) {
// Stop link loops
if (visitedLinks.hasSeen(entryInfo.canonicalFilePath()))
return;
}
if (engine) {
engine->setFileName(path);
if (auto it = engine->beginEntryList(path, iteratorFlags, nameFilters)) {
fileEngineIterators.emplace_back(std::move(it));
} else {
// No iterator; no entry list.
}
} else {
#ifndef QT_NO_FILESYSTEMITERATOR
QFileSystemEntry *fentry = nullptr;
if (entryInfo.fileInfoOpt)
fentry = &entryInfo.fileInfoOpt->d_ptr->fileEntry;
else
fentry = &entryInfo.entry;
nativeIterators.emplace_back(std::make_unique<QFileSystemIterator>(*fentry, iteratorFlags));
#else
qWarning("Qt was built with -no-feature-filesystemiterator: no files/plugins will be found!");
#endif
}
}
bool QDirListingPrivate::entryMatches(QDirEntryInfo &entryInfo)
{
checkAndPushDirectory(entryInfo);
return matchesFilters(entryInfo);
}
/*!
\internal
Advances the internal iterator, either a QAbstractFileEngineIterator (e.g.
QResourceFileEngineIterator) or a QFileSystemIterator (which uses low-level
system methods, e.g. readdir() on Unix). The iterators are stored in a
vector.
A typical example of doing recursive iteration:
- while iterating directory A we find a sub-dir B
- an iterator for B is added to the vector
- B's iterator is processed (vector.back()) first; then the loop
goes back to processing A's iterator
*/
void QDirListingPrivate::advance()
{
// Use get() in both code paths below because the iterator returned by back()
// may be invalidated due to reallocation when appending new iterators in
// pushDirectory().
if (engine) {
while (!fileEngineIterators.empty()) {
// Find the next valid iterator that matches the filters.
QAbstractFileEngineIterator *it;
while (it = fileEngineIterators.back().get(), it->advance()) {
QDirEntryInfo entryInfo;
entryInfo.fileInfoOpt = it->currentFileInfo();
if (entryMatches(entryInfo)) {
currentEntryInfo = std::move(entryInfo);
return;
}
}
fileEngineIterators.pop_back();
}
} else {
#ifndef QT_NO_FILESYSTEMITERATOR
QDirEntryInfo entryInfo;
while (!nativeIterators.empty()) {
// Find the next valid iterator that matches the filters.
QFileSystemIterator *it;
while (it = nativeIterators.back().get(),
it->advance(entryInfo.entry, entryInfo.metaData)) {
if (entryMatches(entryInfo)) {
currentEntryInfo = std::move(entryInfo);
return;
}
entryInfo = {};
}
nativeIterators.pop_back();
}
#endif
}
}
static bool isDotOrDotDot(QStringView fileName)
{
return fileName == "."_L1 || fileName == ".."_L1;
}
void QDirListingPrivate::checkAndPushDirectory(QDirEntryInfo &entryInfo)
{
using F = QDirListing::IteratorFlag;
// If we're doing flat iteration, we're done.
if (!iteratorFlags.testAnyFlags(F::Recursive))
return;
// Follow symlinks only when asked
if (!iteratorFlags.testAnyFlags(F::FollowDirSymlinks) && entryInfo.isSymLink())
return;
// Never follow . and ..
if (isDotOrDotDot(entryInfo.fileName()))
return;
// No hidden directories unless requested
const bool includeHidden = iteratorFlags.testAnyFlags(QDirListing::IteratorFlag::IncludeHidden);
if (!includeHidden && entryInfo.isHidden())
return;
// Never follow non-directory entries
if (!entryInfo.isDir())
return;
pushDirectory(entryInfo);
}
/*!
\internal
This function returns \c true if the current entry matches the filters
(i.e., the current entry will be returned as part of the directory
iteration); otherwise, \c false is returned.
*/
bool QDirListingPrivate::matchesFilters(QDirEntryInfo &entryInfo) const
{
using F = QDirListing::IteratorFlag;
const QString &fileName = entryInfo.fileName();
if (fileName.isEmpty())
return false;
// name filter
#if QT_CONFIG(regularexpression)
const bool skipNameFilters = iteratorFlags.testAnyFlags(F::NoNameFiltersForDirs)
&& entryInfo.isDir();
if (!skipNameFilters) {
if (!regexMatchesName(fileName))
return false;
}
#endif // QT_CONFIG(regularexpression)
if (isDotOrDotDot(fileName))
return iteratorFlags.testFlags(F::IncludeDotAndDotDot);
if (!iteratorFlags.testAnyFlag(F::IncludeHidden) && entryInfo.isHidden())
return false;
const bool includeBrokenSymlinks = iteratorFlags.testAnyFlags(F::IncludeBrokenSymlinks);
if (includeBrokenSymlinks && entryInfo.isSymLink() && !entryInfo.exists())
return true;
if (iteratorFlags.testFlag(F::ResolveSymlinks)) {
if (entryInfo.isSymLink() && !entryInfo.exists())
return false; // Exclude broken symlinks; anything else will be filtered below
} else {
constexpr auto f = F::ExcludeFiles | F::ExcludeDirs | F::ExcludeOther;
const bool filterByTargetType = iteratorFlags.testAnyFlags(f);
if (filterByTargetType && entryInfo.isSymLink())
return false;
}
if (iteratorFlags.testAnyFlag(F::ExcludeOther)
&& !entryInfo.isFile() && !entryInfo.isDir() && !entryInfo.isSymLink()) {
return false;
}
if (iteratorFlags.testAnyFlags(F::ExcludeDirs) && entryInfo.isDir())
return false;
if (iteratorFlags.testAnyFlags(F::ExcludeFiles) && entryInfo.isFile())
return false;
return true;
}
bool QDirListingPrivate::hasIterators() const
{
if (engine)
return !fileEngineIterators.empty();
#if !defined(QT_NO_FILESYSTEMITERATOR)
return !nativeIterators.empty();
#endif
return false;
}
/*!
Constructs a QDirListing that can iterate over \a path.
You can pass options via \a flags to control how the directory should
be iterated.
By default, \a flags is IteratorFlag::Default.
\sa IteratorFlags
*/
QDirListing::QDirListing(const QString &path, IteratorFlags flags)
: d(new QDirListingPrivate)
{
d->initialEntryInfo.entry = QFileSystemEntry(path);
d->iteratorFlags = flags;
d->init();
}
/*!
Constructs a QDirListing that can iterate over \a path.
You can pass options via \a flags to control how the directory should
be iterated. By default, \a flags is IteratorFlag::Default.
The listed entries will be filtered according to the file glob patterns
in \a nameFilters, which are converted to a regular expression using
QRegularExpression::fromWildcard (see QDir::setNameFilters() for more
details).
For example, the following iterator could be used to iterate over audio
files:
\snippet code/src_corelib_io_qdirlisting.cpp 2
Sometimes you can filter by name more efficiently by iterating over the
entries with a range-for loop, using string comparison. For example:
\snippet code/src_corelib_io_qdirlisting.cpp 7
\sa IteratorFlags, QDir::setNameFilters()
*/
QDirListing::QDirListing(const QString &path, const QStringList &nameFilters, IteratorFlags flags)
: d(new QDirListingPrivate)
{
d->initialEntryInfo.entry = QFileSystemEntry(path);
d->nameFilters = nameFilters;
d->iteratorFlags = flags;
d->init();
}
/*!
\fn QDirListing::QDirListing(QDirListing &&other)
Move constructor. Moves \a other into this QDirListing.
//! [partially-formed]
\note The moved-from object \a other is placed in a partially-formed state,
in which the only valid operations are destruction and assignment of a new
value.
//! [partially-formed]
*/
/*!
\fn QDirListing &QDirListing::operator=(QDirListing &&other)
Move-assigns \a other to this QDirListing.
\include qdirlisting.cpp partially-formed
*/
/*!
Destroys the QDirListing.
*/
QDirListing::~QDirListing()
{
delete d;
}
/*!
Returns the directory path used to construct this QDirListing.
*/
QString QDirListing::iteratorPath() const
{
return d->initialEntryInfo.filePath();
}
/*!
Returns the set of IteratorFlags used to construct this QDirListing.
*/
QDirListing::IteratorFlags QDirListing::iteratorFlags() const
{
return d->iteratorFlags;
}
/*!
Returns the list of file name glob filters used to construct this
QDirListing.
*/
QStringList QDirListing::nameFilters() const
{
return d->nameFilters;
}
/*!
\class QDirListing::const_iterator
\since 6.8
\inmodule QtCore
\ingroup io
The iterator type returned by QDirListing::cbegin().
//! [dirlisting-iterator-behavior]
\list
\li This is a forward-only, single-pass iterator (you cannot iterate
directory entries in reverse order)
\li Can't be copied, only \c{std::move()}d.
\li \include qdirlisting.cpp post-increment-partially-formed
\li Doesn't allow random access
\li Can be used in ranged-for loops; or with C++20 std::ranges algorithms
that don't require random access iterators
\li Dereferencing a valid iterator returns a \c{const DirEntry &}
\li (c)end() returns a \l QDirListing::sentinel that signals the end of
the iteration. Dereferencing an iterator that compares equal to end()
is undefined behavior
\endlist
//! [dirlisting-iterator-behavior]
\include qdirlisting.cpp ranges-algorithms-note
\sa QDirListing, QDirListing::sentinel, QDirListing::DirEntry
*/
/*!
\typealias QDirListing::const_iterator::reference
A typedef for \c {const QDirListing::DirEntry &}.
*/
/*!
\typealias QDirListing::const_iterator::pointer
A typedef for \c {const QDirListing::DirEntry *}.
*/
/*!
\class QDirListing::sentinel
\since 6.8
\inmodule QtCore
\ingroup io
\l QDirListing returns an object of this type to signal the end of
iteration. Dereferencing a \l QDirListing::const_iterator that is
equal to \c sentinel{} is undefined behavior.
\include qdirlisting.cpp ranges-algorithms-note
\sa QDirListing, QDirListing::const_iterator, QDirListing::DirEntry
*/
/*!
\fn QDirListing::const_iterator QDirListing::begin() const
\fn QDirListing::const_iterator QDirListing::cbegin() const
\fn QDirListing::sentinel QDirListing::end() const
\fn QDirListing::sentinel QDirListing::cend() const
(c)begin() returns a QDirListing::const_iterator that can be used to
iterate over directory entries.
\include qdirlisting.cpp dirlisting-iterator-behavior
\note Each time (c)begin() is called on the same QDirListing object,
the internal state is reset and the iteration starts anew.
(Some of the above restrictions are dictated by the underlying system
library functions' implementation).
For example:
\snippet code/src_corelib_io_qdirlisting.cpp 0
Here's how to find and read all files filtered by name, recursively:
\snippet code/src_corelib_io_qdirlisting.cpp 1
//! [ranges-algorithms-note]
\note The "classical" STL algorithms don't support iterator/sentinel, so
you need to use C++20 std::ranges algorithms for QDirListing, or else a
3rd-party library that provides range-based algorithms in C++17.
//! [ranges-algorithms-note]
\sa QDirListing::DirEntry
*/
QDirListing::const_iterator QDirListing::begin() const
{
d->beginIterating();
const_iterator it{d};
++it;
return it;
}
/*!
\fn const QDirListing::DirEntry &QDirListing::const_iterator::operator*() const
Returns a \c{const QDirListing::DirEntry &} of the directory entry this
iterator points to.
*/
/*!
\fn const QDirListing::DirEntry *QDirListing::const_iterator::operator->() const
Returns a \c{const QDirListing::DirEntry *} to the directory entry this
iterator points to.
*/
/*!
\fn QDirListing::const_iterator::operator++()
Pre-increment operator.
Advances the iterator and returns a reference to it.
*/
/*!
\fn void QDirListing::const_iterator::operator++(int)
Post-increment operator.
\include qdirlisting.cpp std-input-iterator-tag
//! [post-increment-partially-formed]
The return value of post-increment on objects that model
\c std::input_iterator is partially-formed (a copy of an iterator that
has since been advanced), the only valid operations on such an object
are destruction and assignment of a new iterator. Therefore the
post-increment operator advances the iterator and returns \c void.
//! [post-increment-partially-formed]
*/
/*!
\internal
Implements the actual advancing. Not a member function to avoid forcing
DirEntry objects (and therefore const_iterator ones) onto the stack.
*/
auto QDirListing::next(DirEntry dirEntry) -> DirEntry
{
dirEntry.dirListPtr->advance();
if (!dirEntry.dirListPtr->hasIterators())
return {}; // All done, make `this` equal to the end() iterator
return dirEntry;
}
/*!
\class QDirListing::DirEntry
\inmodule QtCore
\ingroup io
Dereferencing a valid QDirListing::const_iterator returns a DirEntry
object.
DirEntry offers a subset of QFileInfo's API (for example, fileName(),
filePath(), exists()). Internally, DirEntry only constructs a QFileInfo
object if needed, that is, if the info hasn't been already fetched
by other system functions. You can use DirEntry::fileInfo() to get a
QFileInfo. For example:
\snippet code/src_corelib_io_qdirlisting.cpp 3
\snippet code/src_corelib_io_qdirlisting.cpp 4
*/
/*!
\fn QFileInfo QDirListing::DirEntry::fileInfo() const
\fn QString QDirListing::DirEntry::fileName() const
\fn QString QDirListing::DirEntry::baseName() const
\fn QString QDirListing::DirEntry::completeBaseName() const
\fn QString QDirListing::DirEntry::suffix() const
\fn QString QDirListing::DirEntry::bundleName() const
\fn QString QDirListing::DirEntry::completeSuffix() const
\fn QString QDirListing::DirEntry::filePath() const
\fn QString QDirListing::DirEntry::canonicalFilePath() const
\fn QString QDirListing::DirEntry::absoluteFilePath() const
\fn QString QDirListing::DirEntry::absolutePath() const
\fn bool QDirListing::DirEntry::isDir() const
\fn bool QDirListing::DirEntry::isFile() const
\fn bool QDirListing::DirEntry::isSymLink() const
\fn bool QDirListing::DirEntry::exists() const
\fn bool QDirListing::DirEntry::isHidden() const
\fn bool QDirListing::DirEntry::isReadable() const
\fn bool QDirListing::DirEntry::isWritable() const
\fn bool QDirListing::DirEntry::isExecutable() const
\fn qint64 QDirListing::DirEntry::size() const
\fn QDateTime QDirListing::DirEntry::fileTime(QFile::FileTime type, const QTimeZone &tz) const
\fn QDateTime QDirListing::DirEntry::birthTime(const QTimeZone &tz) const;
\fn QDateTime QDirListing::DirEntry::metadataChangeTime(const QTimeZone &tz) const;
\fn QDateTime QDirListing::DirEntry::lastModified(const QTimeZone &tz) const;
\fn QDateTime QDirListing::DirEntry::lastRead(const QTimeZone &tz) const;
See the QFileInfo methods with the same names.
*/
QFileInfo QDirListing::DirEntry::fileInfo() const
{
return dirListPtr->currentEntryInfo.fileInfo();
}
QString QDirListing::DirEntry::fileName() const
{
return dirListPtr->currentEntryInfo.fileName();
}
QString QDirListing::DirEntry::baseName() const
{
return dirListPtr->currentEntryInfo.baseName();
}
QString QDirListing::DirEntry::completeBaseName() const
{
return dirListPtr->currentEntryInfo.completeBaseName();
}
QString QDirListing::DirEntry::suffix() const
{
return dirListPtr->currentEntryInfo.suffix();
}
QString QDirListing::DirEntry::bundleName() const
{
return dirListPtr->currentEntryInfo.bundleName();
}
QString QDirListing::DirEntry::completeSuffix() const
{
return dirListPtr->currentEntryInfo.completeSuffix();
}
QString QDirListing::DirEntry::filePath() const
{
return dirListPtr->currentEntryInfo.filePath();
}
QString QDirListing::DirEntry::canonicalFilePath() const
{
return dirListPtr->currentEntryInfo.canonicalFilePath();
}
QString QDirListing::DirEntry::absoluteFilePath() const
{
return dirListPtr->currentEntryInfo.absoluteFilePath();
}
QString QDirListing::DirEntry::absolutePath() const
{
return dirListPtr->currentEntryInfo.absolutePath();
}
bool QDirListing::DirEntry::isDir() const
{
return dirListPtr->currentEntryInfo.isDir();
}
bool QDirListing::DirEntry::isFile() const
{
return dirListPtr->currentEntryInfo.isFile();
}
bool QDirListing::DirEntry::isSymLink() const
{
return dirListPtr->currentEntryInfo.isSymLink();
}
bool QDirListing::DirEntry::exists() const
{
return dirListPtr->currentEntryInfo.exists();
}
bool QDirListing::DirEntry::isHidden() const
{
return dirListPtr->currentEntryInfo.isHidden();
}
bool QDirListing::DirEntry::isReadable() const
{
return dirListPtr->currentEntryInfo.isReadable();
}
bool QDirListing::DirEntry::isWritable() const
{
return dirListPtr->currentEntryInfo.isWritable();
}
bool QDirListing::DirEntry::isExecutable() const
{
return dirListPtr->currentEntryInfo.isExecutable();
}
qint64 QDirListing::DirEntry::size() const
{
return dirListPtr->currentEntryInfo.size();
}
QDateTime QDirListing::DirEntry::fileTime(QFile::FileTime type, const QTimeZone &tz) const
{
return dirListPtr->currentEntryInfo.fileTime(type, tz);
}
#ifndef QT_NO_DEBUG_STREAM
/*
Since 6.11.
*/
QDebug operator<<(QDebug debug, QDirListing::IteratorFlags flags)
{
QDebugStateSaver save(debug);
debug.resetFormat();
QByteArray ret = "QDirListing::IteratorFlags(";
using F = QDirListing::IteratorFlag;
if (flags.testFlags(F::Default))
ret += "Default|";
if (flags.testFlags(F::ExcludeFiles))
ret += "ExcludeFiles|";
if (flags.testFlags(F::ExcludeDirs))
ret += "ExcludeDirs|";
if (flags.testFlags(F::ExcludeOther))
ret += "ExcludeOther|";
if (flags.testFlags(F::ResolveSymlinks))
ret += "ResolveSymlinks|";
// if (flags.testFlags(F::FilesOnly)) // covered by F::ExcludeDirs | F::ExcludeOther
// ret += "FilesOnly|";
// if (flags.testFlags(F::DirsOnly)) // covered by F::ExcludeFiles | F::ExcludeOther
// ret += "DirsOnly|";
if (flags.testFlags(F::IncludeHidden))
ret += "IncludeHidden|";
if (flags.testFlags(F::IncludeDotAndDotDot))
ret += "IncludeDotAndDotDot|";
if (flags.testFlags(F::CaseSensitive))
ret += "CaseSensitive|";
if (flags.testFlags(F::Recursive))
ret += "Recursive|";
if (flags.testFlags(F::FollowDirSymlinks))
ret += "FollowDirSymlinks|";
if (flags.testFlags(F::IncludeBrokenSymlinks))
ret += "IncludeBrokenSymlinks|";
if (flags.testFlags(F::NoNameFiltersForDirs))
ret += "NoNameFiltersForDirs|";
if (ret.endsWith('|'))
ret.chop(1);
ret += ')';
debug.noquote() << ret;
return debug;
}
#endif
QT_END_NAMESPACE
|