Struct qt_core::QDirIterator
source · #[repr(C)]pub struct QDirIterator { /* private fields */ }
Expand description
The QDirIterator class provides an iterator for directory entrylists.
C++ class: QDirIterator
.
The QDirIterator class provides an iterator for directory entrylists.
You can use QDirIterator 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(), QDirIterator does not support sorting.
The QDirIterator constructor takes a QDir or a directory as argument. After construction, the iterator is located before the first directory entry. Here's how to iterate over all the entries sequentially:
QDirIterator it(“/etc”, QDirIterator::Subdirectories); while (it.hasNext()) { qDebug() << it.next();
// /etc/. // /etc/.. // /etc/X11 // /etc/X11/fs // … }
Here's how to find and read all files filtered by name, recursively:
QDirIterator it(“/sys”, QStringList() << “scaling_cur_freq”, QDir::NoFilter, QDirIterator::Subdirectories); while (it.hasNext()) { QFile f(it.next()); f.open(QIODevice::ReadOnly); qDebug() << f.fileName() << f.readAll().trimmed().toDouble() / 1000 << “MHz”; }
The next() function returns the path to the next directory entry and advances the iterator. You can also call filePath() to get the current file path without advancing the iterator. The fileName() function returns only the name of the file, similar to how QDir::entryList() works. You can also call fileInfo() to get a QFileInfo for the current entry.
Unlike Qt's container iterators, QDirIterator is uni-directional (i.e., you cannot iterate directories in reverse order) and does not allow random access.
Implementations§
source§impl QDirIterator
impl QDirIterator
sourcepub unsafe fn file_info(&self) -> CppBox<QFileInfo>
pub unsafe fn file_info(&self) -> CppBox<QFileInfo>
Returns a QFileInfo for the current directory entry.
Calls C++ function: QFileInfo QDirIterator::fileInfo() const
.
sourcepub unsafe fn file_name(&self) -> CppBox<QString>
pub unsafe fn file_name(&self) -> CppBox<QString>
Returns the file name for the current directory entry, without the path prepended.
Calls C++ function: QString QDirIterator::fileName() const
.
Returns the file name for the current directory entry, without the path prepended.
This function is convenient when iterating a single directory. When using the QDirIterator::Subdirectories flag, you can use filePath() to get the full path.
sourcepub unsafe fn file_path(&self) -> CppBox<QString>
pub unsafe fn file_path(&self) -> CppBox<QString>
Returns the full file path for the current directory entry.
Calls C++ function: QString QDirIterator::filePath() const
.
sourcepub unsafe fn has_next(&self) -> bool
pub unsafe fn has_next(&self) -> bool
Returns true
if there is at least one more entry in the directory; otherwise, false is returned.
Calls C++ function: bool QDirIterator::hasNext() const
.
sourcepub unsafe fn from_q_dir_q_flags_iterator_flag(
dir: impl CastInto<Ref<QDir>>,
flags: QFlags<IteratorFlag>
) -> CppBox<QDirIterator>
pub unsafe fn from_q_dir_q_flags_iterator_flag( dir: impl CastInto<Ref<QDir>>, flags: QFlags<IteratorFlag> ) -> CppBox<QDirIterator>
Constructs a QDirIterator that can iterate over dir's entrylist, using dir's name filters and regular filters. You can pass options via flags to decide how the directory should be iterated.
Calls C++ function: [constructor] void QDirIterator::QDirIterator(const QDir& dir, QFlags<QDirIterator::IteratorFlag> flags = …)
.
Constructs a QDirIterator that can iterate over dir’s entrylist, using dir’s name filters and regular filters. You can pass options via flags to decide how the directory should be iterated.
By default, flags is NoIteratorFlags, which provides the same behavior as in QDir::entryList().
The sorting in dir is ignored.
Note: To list symlinks that point to non existing files, QDir::System must be passed to the flags.
See also hasNext(), next(), and IteratorFlags.
sourcepub unsafe fn from_q_string_q_flags_iterator_flag(
path: impl CastInto<Ref<QString>>,
flags: QFlags<IteratorFlag>
) -> CppBox<QDirIterator>
pub unsafe fn from_q_string_q_flags_iterator_flag( path: impl CastInto<Ref<QString>>, flags: QFlags<IteratorFlag> ) -> CppBox<QDirIterator>
Constructs a QDirIterator that can iterate over path. You can pass options via flags to decide how the directory should be iterated.
Calls C++ function: [constructor] void QDirIterator::QDirIterator(const QString& path, QFlags<QDirIterator::IteratorFlag> flags = …)
.
Constructs a QDirIterator that can iterate over path. You can pass options via flags to decide how the directory should be iterated.
By default, flags is NoIteratorFlags, which provides the same behavior as in QDir::entryList().
Note: To list symlinks that point to non existing files, QDir::System must be passed to the flags.
See also hasNext(), next(), and IteratorFlags.
sourcepub unsafe fn from_q_string_q_flags_filter_q_flags_iterator_flag(
path: impl CastInto<Ref<QString>>,
filter: QFlags<Filter>,
flags: QFlags<IteratorFlag>
) -> CppBox<QDirIterator>
pub unsafe fn from_q_string_q_flags_filter_q_flags_iterator_flag( path: impl CastInto<Ref<QString>>, filter: QFlags<Filter>, flags: QFlags<IteratorFlag> ) -> CppBox<QDirIterator>
Constructs a QDirIterator that can iterate over path, with no name filtering and filters for entry filtering. You can pass options via flags to decide how the directory should be iterated.
Calls C++ function: [constructor] void QDirIterator::QDirIterator(const QString& path, QFlags<QDir::Filter> filter, QFlags<QDirIterator::IteratorFlag> flags = …)
.
Constructs a QDirIterator that can iterate over path, with no name filtering and filters for entry filtering. You can pass options via flags to decide how the directory should be iterated.
By default, filters is QDir::NoFilter, and flags is NoIteratorFlags, which provides the same behavior as in QDir::entryList().
Note: To list symlinks that point to non existing files, QDir::System must be passed to the flags.
See also hasNext(), next(), and IteratorFlags.
sourcepub unsafe fn from_q_string_q_string_list_q_flags_filter_q_flags_iterator_flag(
path: impl CastInto<Ref<QString>>,
name_filters: impl CastInto<Ref<QStringList>>,
filters: QFlags<Filter>,
flags: QFlags<IteratorFlag>
) -> CppBox<QDirIterator>
pub unsafe fn from_q_string_q_string_list_q_flags_filter_q_flags_iterator_flag( path: impl CastInto<Ref<QString>>, name_filters: impl CastInto<Ref<QStringList>>, filters: QFlags<Filter>, flags: QFlags<IteratorFlag> ) -> CppBox<QDirIterator>
Constructs a QDirIterator that can iterate over path, using nameFilters and filters. You can pass options via flags to decide how the directory should be iterated.
Calls C++ function: [constructor] void QDirIterator::QDirIterator(const QString& path, const QStringList& nameFilters, QFlags<QDir::Filter> filters = …, QFlags<QDirIterator::IteratorFlag> flags = …)
.
Constructs a QDirIterator that can iterate over path, using nameFilters and filters. You can pass options via flags to decide how the directory should be iterated.
By default, flags is NoIteratorFlags, which provides the same behavior as QDir::entryList().
Note: To list symlinks that point to non existing files, QDir::System must be passed to the flags.
See also hasNext(), next(), and IteratorFlags.
sourcepub unsafe fn from_q_dir(dir: impl CastInto<Ref<QDir>>) -> CppBox<QDirIterator>
pub unsafe fn from_q_dir(dir: impl CastInto<Ref<QDir>>) -> CppBox<QDirIterator>
Constructs a QDirIterator that can iterate over dir's entrylist, using dir's name filters and regular filters. You can pass options via flags to decide how the directory should be iterated.
Calls C++ function: [constructor] void QDirIterator::QDirIterator(const QDir& dir)
.
Constructs a QDirIterator that can iterate over dir’s entrylist, using dir’s name filters and regular filters. You can pass options via flags to decide how the directory should be iterated.
By default, flags is NoIteratorFlags, which provides the same behavior as in QDir::entryList().
The sorting in dir is ignored.
Note: To list symlinks that point to non existing files, QDir::System must be passed to the flags.
See also hasNext(), next(), and IteratorFlags.
sourcepub unsafe fn from_q_string(
path: impl CastInto<Ref<QString>>
) -> CppBox<QDirIterator>
pub unsafe fn from_q_string( path: impl CastInto<Ref<QString>> ) -> CppBox<QDirIterator>
Constructs a QDirIterator that can iterate over path. You can pass options via flags to decide how the directory should be iterated.
Calls C++ function: [constructor] void QDirIterator::QDirIterator(const QString& path)
.
Constructs a QDirIterator that can iterate over path. You can pass options via flags to decide how the directory should be iterated.
By default, flags is NoIteratorFlags, which provides the same behavior as in QDir::entryList().
Note: To list symlinks that point to non existing files, QDir::System must be passed to the flags.
See also hasNext(), next(), and IteratorFlags.
sourcepub unsafe fn from_q_string_q_flags_filter(
path: impl CastInto<Ref<QString>>,
filter: QFlags<Filter>
) -> CppBox<QDirIterator>
pub unsafe fn from_q_string_q_flags_filter( path: impl CastInto<Ref<QString>>, filter: QFlags<Filter> ) -> CppBox<QDirIterator>
Constructs a QDirIterator that can iterate over path, with no name filtering and filters for entry filtering. You can pass options via flags to decide how the directory should be iterated.
Calls C++ function: [constructor] void QDirIterator::QDirIterator(const QString& path, QFlags<QDir::Filter> filter)
.
Constructs a QDirIterator that can iterate over path, with no name filtering and filters for entry filtering. You can pass options via flags to decide how the directory should be iterated.
By default, filters is QDir::NoFilter, and flags is NoIteratorFlags, which provides the same behavior as in QDir::entryList().
Note: To list symlinks that point to non existing files, QDir::System must be passed to the flags.
See also hasNext(), next(), and IteratorFlags.
sourcepub unsafe fn from_q_string_q_string_list_q_flags_filter(
path: impl CastInto<Ref<QString>>,
name_filters: impl CastInto<Ref<QStringList>>,
filters: QFlags<Filter>
) -> CppBox<QDirIterator>
pub unsafe fn from_q_string_q_string_list_q_flags_filter( path: impl CastInto<Ref<QString>>, name_filters: impl CastInto<Ref<QStringList>>, filters: QFlags<Filter> ) -> CppBox<QDirIterator>
Constructs a QDirIterator that can iterate over path, using nameFilters and filters. You can pass options via flags to decide how the directory should be iterated.
Calls C++ function: [constructor] void QDirIterator::QDirIterator(const QString& path, const QStringList& nameFilters, QFlags<QDir::Filter> filters = …)
.
Constructs a QDirIterator that can iterate over path, using nameFilters and filters. You can pass options via flags to decide how the directory should be iterated.
By default, flags is NoIteratorFlags, which provides the same behavior as QDir::entryList().
Note: To list symlinks that point to non existing files, QDir::System must be passed to the flags.
See also hasNext(), next(), and IteratorFlags.
sourcepub unsafe fn from_q_string_q_string_list(
path: impl CastInto<Ref<QString>>,
name_filters: impl CastInto<Ref<QStringList>>
) -> CppBox<QDirIterator>
pub unsafe fn from_q_string_q_string_list( path: impl CastInto<Ref<QString>>, name_filters: impl CastInto<Ref<QStringList>> ) -> CppBox<QDirIterator>
Constructs a QDirIterator that can iterate over path, using nameFilters and filters. You can pass options via flags to decide how the directory should be iterated.
Calls C++ function: [constructor] void QDirIterator::QDirIterator(const QString& path, const QStringList& nameFilters)
.
Constructs a QDirIterator that can iterate over path, using nameFilters and filters. You can pass options via flags to decide how the directory should be iterated.
By default, flags is NoIteratorFlags, which provides the same behavior as QDir::entryList().
Note: To list symlinks that point to non existing files, QDir::System must be passed to the flags.
See also hasNext(), next(), and IteratorFlags.
sourcepub unsafe fn next(&self) -> CppBox<QString>
pub unsafe fn next(&self) -> CppBox<QString>
Advances the iterator to the next entry, and returns the file path of this new entry. If hasNext() returns false
, this function does nothing, and returns an empty QString.
Calls C++ function: QString QDirIterator::next()
.
Advances the iterator to the next entry, and returns the file path of this new entry. If hasNext() returns false
, this function does nothing, and returns an empty QString.
You can call fileName() or filePath() to get the current entry file name or path, or fileInfo() to get a QFileInfo for the current entry.
Trait Implementations§
source§impl CppDeletable for QDirIterator
impl CppDeletable for QDirIterator
source§unsafe fn delete(&self)
unsafe fn delete(&self)
Destroys the QDirIterator.
Calls C++ function: [destructor] void QDirIterator::~QDirIterator()
.
Destroys the QDirIterator.