#include#include int main() { QDir dir("/home/user/Documents"); QFileInfoList fileInfoList = dir.entryInfoList(); for (const QFileInfo& fileInfo : fileInfoList) { if (fileInfo.isDir()) { qDebug() << "Found directory:" << fileInfo.fileName(); } else { qDebug() << "Found file:" << fileInfo.fileName(); } } return 0; }
#includeThis example code retrieves a list of QFileInfo objects for all files in the "/home/user/Documents" directory that match the "*.txt" name filter. The `entryInfoList()` method is called with the `QDir::Files` flag to get only files and not directories. The code then prints the absolute file path of each file in the list to the console. Package library: Qt Core module#include int main() { QDir dir("/home/user/Documents"); QStringList nameFilters("*.txt"); QFileInfoList fileInfoList = dir.entryInfoList(nameFilters, QDir::Files); for (const QFileInfo& fileInfo : fileInfoList) { qDebug() << "Found file:" << fileInfo.absoluteFilePath(); } return 0; }