![]() |
Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
#include <qdirlisting.h>
Classes | |
class | const_iterator |
class | DirEntry |
\inmodule QtCore More... | |
class | sentinel |
\typealias QDirListing::const_iterator::reference More... | |
Public Types | |
enum class | IteratorFlag { Default = 0x000000 , ExcludeFiles = 0x000004 , ExcludeDirs = 0x000008 , ExcludeOther = 0x000010 , ResolveSymlinks = 0x000020 , FilesOnly = ExcludeDirs | ExcludeOther , DirsOnly = ExcludeFiles | ExcludeOther , IncludeHidden = 0x000040 , IncludeDotAndDotDot = 0x000080 , CaseSensitive = 0x000100 , Recursive = 0x000400 , FollowDirSymlinks = 0x000800 } |
This enum class describes flags that can be used to configure the behavior of QDirListing. More... | |
Public Member Functions | |
Q_CORE_EXPORT | QDirListing (const QString &path, IteratorFlags flags=IteratorFlag::Default) |
Constructs a QDirListing that can iterate over path. | |
Q_CORE_EXPORT | QDirListing (const QString &path, const QStringList &nameFilters, IteratorFlags flags=IteratorFlag::Default) |
Constructs a QDirListing that can iterate over path. | |
QDirListing (QDirListing &&other) noexcept | |
void | swap (QDirListing &other) noexcept |
Q_CORE_EXPORT | ~QDirListing () |
Destroys the QDirListing. | |
Q_CORE_EXPORT QString | iteratorPath () const |
Returns the directory path used to construct this QDirListing. | |
Q_CORE_EXPORT IteratorFlags | iteratorFlags () const |
Returns the set of IteratorFlags used to construct this QDirListing. | |
Q_CORE_EXPORT QStringList | nameFilters () const |
Returns the list of file name glob filters used to construct this QDirListing. | |
Q_CORE_EXPORT const_iterator | begin () const |
const_iterator | cbegin () const |
sentinel | end () const |
sentinel | cend () const |
const_iterator | constBegin () const |
sentinel | constEnd () const |
Friends | |
class | QDir |
class | QDirPrivate |
class | QDirIteratorPrivate |
class | QAbstractFileEngine |
class | QFileInfoGatherer |
Definition at line 24 of file qdirlisting.h.
|
strong |
This enum class describes flags that can be used to configure the behavior of QDirListing.
\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:
Values from this enumerator can be bitwise OR'ed together.
\value Default List all files, directories and symbolic links, including broken symlinks (where the target doesn't exist). Hidden files and directories and the special entries {.} and
{..} 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 Don't list file system entries that are not directories, regular files, or symbolic links. \list
mknod}
manual page.
.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. With this flag, broken symbolic links (where the target doesn't exist) are excluded. 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 {
.} and {..} 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.
Enumerator | |
---|---|
Default | |
ExcludeFiles | |
ExcludeDirs | |
ExcludeOther | |
ResolveSymlinks | |
FilesOnly | |
DirsOnly | |
IncludeHidden | |
IncludeDotAndDotDot | |
CaseSensitive | |
Recursive | |
FollowDirSymlinks |
Definition at line 27 of file qdirlisting.h.
|
explicit |
Constructs a QDirListing that can iterate over path.
You can pass options via flags to control how the directory should be iterated.
By default, flags is IteratorFlag::Default.
Definition at line 561 of file qdirlisting.cpp.
References QDirListingPrivate::init().
|
explicit |
Constructs a QDirListing that can iterate over path.
You can pass options via flags to control how the directory should be iterated. By default, flags is IteratorFlag::Default.
The listed entries will be filtered according to the file glob patterns in nameFilters (see QDir::setNameFilters() for more details).
For example, the following iterator could be used to iterate over audio files:
Definition at line 585 of file qdirlisting.cpp.
References QDirListingPrivate::init().
|
inlinenoexcept |
Definition at line 49 of file qdirlisting.h.
QDirListing::~QDirListing | ( | ) |
Destroys the QDirListing.
Definition at line 639 of file qdirlisting.cpp.
QDirListing::const_iterator QDirListing::begin | ( | ) | const |
\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]
\sa QDirListing::DirEntry
Definition at line 756 of file qdirlisting.cpp.
References QDirListingPrivate::beginIterating(), and QDirListing::const_iterator::operator++().
|
inline |
Definition at line 139 of file qdirlisting.h.
|
inline |
Definition at line 141 of file qdirlisting.h.
References end().
|
inline |
Definition at line 144 of file qdirlisting.h.
|
inline |
Definition at line 145 of file qdirlisting.h.
References end().
|
inline |
Definition at line 140 of file qdirlisting.h.
Referenced by cend(), and constEnd().
QDirListing::IteratorFlags QDirListing::iteratorFlags | ( | ) | const |
Returns the set of IteratorFlags used to construct this QDirListing.
Definition at line 655 of file qdirlisting.cpp.
QString QDirListing::iteratorPath | ( | ) | const |
Returns the directory path used to construct this QDirListing.
Definition at line 647 of file qdirlisting.cpp.
QStringList QDirListing::nameFilters | ( | ) | const |
Returns the list of file name glob filters used to construct this QDirListing.
Definition at line 664 of file qdirlisting.cpp.
|
inlinenoexcept |
Definition at line 53 of file qdirlisting.h.
|
friend |
Definition at line 163 of file qdirlisting.h.
|
friend |
Definition at line 160 of file qdirlisting.h.
|
friend |
Definition at line 162 of file qdirlisting.h.
|
friend |
Definition at line 161 of file qdirlisting.h.
|
friend |
Definition at line 164 of file qdirlisting.h.